ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-01-13 08:29:44
Exec Total Coverage
Lines: 2808 8318 33.8%
Functions: 77 292 26.4%
Branches: 2440 7250 33.7%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "md5.h"
33 #include "zc/zc_custom.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include <fmt/format.h>
47 #include <filesystem>
48
49 #ifdef __EMSCRIPTEN__
50 #include "base/emscripten_utils.h"
51 #endif
52
53 namespace fs = std::filesystem;
54
55 using namespace util;
56
57 extern ZModule zcm;
58 extern zcmodule moduledata;
59 extern uint8_t ViewLayer3BG, ViewLayer2BG;
60 extern int32_t LayerDitherBG, LayerDitherSz;
61 extern bool NoHighlightLayer0;
62
63 using std::string;
64 using std::pair;
65 #define EPSILON 0.01 // Define your own tolerance
66 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
67
68 #define COLOR_SOLID vc(4)
69 #define COLOR_SLOPE vc(13)
70 #define COLOR_LADDER vc(6)
71 //#define COLOR_EFFECT vc(10)
72
73 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
74 extern char msgbuf[MSG_NEW_SIZE*8];
75
76 extern string zScript;
77
78 9 zmap Map;
79 int32_t prv_mode=0;
80 int16_t ffposx[MAXFFCS];
81 int16_t ffposy[MAXFFCS];
82 int32_t ffprvx[MAXFFCS];
83 int32_t ffprvy[MAXFFCS];
84 void init_ffpos()
85 {
86 for (word q = 0; q < MAXFFCS; ++q)
87 {
88 ffposx[q] = -1000;
89 ffposy[q] = -1000;
90 ffprvx[q] = -10000000;
91 ffprvy[q] = -10000000;
92 }
93 }
94
95 bool save_warn=true;
96
97 int32_t COMBOPOS(int32_t x, int32_t y)
98 {
99 return (((y) & 0xF0) + ((x) >> 4));
100 }
101 int32_t COMBOPOS_B(int32_t x, int32_t y)
102 {
103 if(unsigned(x) >= 256 || unsigned(y) >= 176)
104 return -1;
105 return COMBOPOS(x,y);
106 }
107 int32_t COMBOX(int32_t pos)
108 {
109 return ((pos) % 16 * 16);
110 }
111 int32_t COMBOY(int32_t pos)
112 {
113 return ((pos) & 0xF0);
114 }
115
116 void reset_dmap(int32_t index)
117 {
118 bound(index,0,MAXDMAPS-1);
119 DMaps[index].clear();
120 DMaps[index].title = "";
121 sprintf(DMaps[index].intro, " ");
122 }
123
124 void reset_dmaps()
125 {
126 for(int32_t i=0; i<MAXDMAPS; i++)
127 reset_dmap(i);
128 }
129
130 void truncate_dmap_title(std::string& title)
131 {
132 title.resize(21, ' ');
133 }
134
135 mapscr* zmap::get_prvscr()
136 {
137 return &prvscr;
138 }
139
140
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 zmap::zmap()
141 {
142 18 can_paste=false;
143 18 prv_cmbcycle=0;
144 18 prv_advance=0;
145 18 prv_freeze=0;
146 18 copyffc=-1;
147
148 18 memset(scrpos, 0, sizeof(scrpos));
149 18 memset(scrview, 0, sizeof(scrview));
150 18 screens=NULL;
151 18 prv_time=0;
152 18 prv_scr=0;
153 18 prv_map=0;
154 18 copyscr=0;
155 18 cursor={};
156 copymap=0;
157 layer_target_map = 0;
158 layer_target_scr = 0;
159 layer_target_multiple = 0;
160 18 }
161
162 9 void zmap::clear()
163 {
164
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
165 9 }
166 void zmap::force_refr_pointer()
167 {
168 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
169 screens = nullptr;
170 else screens = &TheMaps[cursor.map*MAPSCRS];
171 }
172 bool zmap::CanUndo()
173 {
174 return undo_stack.size() > 0;
175 }
176 bool zmap::CanRedo()
177 {
178 return redo_stack.size() > 0;
179 }
180 bool zmap::CanPaste()
181 {
182 return can_paste;
183 }
184 int32_t zmap::CopyScr()
185 {
186 return (copymap<<8)+copyscr;
187 }
188 int32_t zmap::getCopyFFC()
189 {
190 return copyffc;
191 }
192 set_ffc_command::data_t zmap::getCopyFFCData()
193 {
194 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
195 }
196 29 int32_t zmap::getMapCount()
197 {
198 29 return map_count;
199 }
200 int32_t zmap::getLayerTargetMap()
201 {
202 return layer_target_map;
203 }
204 int32_t zmap::getLayerTargetScr()
205 {
206 return layer_target_scr;
207 }
208 int32_t zmap::getLayerTargetMultiple()
209 {
210 return layer_target_multiple;
211 }
212 bool zmap::isDungeon(int32_t scr)
213 {
214 for(int32_t i=0; i<4; i++)
215 {
216 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
217 {
218 return false;
219 }
220 }
221
222 return true;
223 }
224
225 bool zmap::clearall(bool validate)
226 {
227 Color=0;
228 char tbuf[10];
229
230 if((header.templatepath[0]!=0)&&validate)
231 {
232 if(!valid_zqt(header.templatepath))
233 {
234 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
235 return false;
236 }
237 }
238
239 for(int32_t i=0; i<map_count; i++)
240 {
241 setCurrMap(i);
242 sprintf(tbuf, "%d", i);
243 clearmap(true);
244 }
245
246 setCurrMap(0);
247 return true;
248 }
249
250 bool zmap::reset_templates(bool validate)
251 {
252 //why are we doing this?
253 if(colordata==NULL)
254 {
255 return false;
256 }
257
258 //int32_t ret;
259 word version, build, dummy, sversion=0;
260 byte dummyc;
261 word dummyw;
262 //int32_t section_size;
263 word temp_map_count;
264 mapscr temp_mapscr;
265 PACKFILE *f=NULL;
266
267 // setPackfilePassword(datapwd);
268 f=open_quest_template(&header, "modules/classic/default.qst", validate);
269 get_version_and_build(f, &version, &build);
270
271 if(!find_section(f, ID_MAPS))
272 {
273 // setPackfilePassword(NULL);
274 return false;
275 }
276
277 //section version info
278 if(!p_igetw(&sversion,f))
279 {
280 return false;
281 }
282
283 if(!p_igetw(&dummy,f))
284 {
285 return false;
286 }
287
288 //section size
289 dword dummy_size;
290 if(!p_igetl(&dummy_size,f))
291 {
292 return false;
293 }
294
295 //finally... section data
296 if(!p_igetw(&temp_map_count,f))
297 {
298 return false;
299 }
300
301 if(version>12)
302 {
303 if(!p_getc(&dummyc,f))
304 return qe_invalid;
305
306 if(!p_getc(&dummyc,f))
307 return qe_invalid;
308
309 if(!p_igetw(&dummyw,f))
310 return qe_invalid;
311
312 if(!p_igetw(&dummyw,f))
313 return qe_invalid;
314
315 if(!p_igetw(&dummyw,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_igetw(&dummyw,f))
328 return qe_invalid;
329
330 if(!p_igetw(&dummyw,f))
331 return qe_invalid;
332
333 if(!p_igetw(&dummyw,f))
334 return qe_invalid;
335
336 if(!p_igetw(&dummyw,f))
337 return qe_invalid;
338
339 if(!p_getc(&dummyc,f))
340 return qe_invalid;
341
342 if(!p_getc(&dummyc,f))
343 return qe_invalid;
344 }
345
346 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
347 {
348 readmapscreen(f, &header, &temp_mapscr, sversion);
349 }
350
351 readmapscreen(f, &header, &TheMaps[128], sversion);
352 readmapscreen(f, &header, &TheMaps[129], sversion);
353
354 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
355 {
356 readmapscreen(f, &header, &temp_mapscr, sversion);
357 }
358
359 if(version>12)
360 {
361 if(!p_getc(&dummyc,f))
362 return qe_invalid;
363
364 if(!p_getc(&dummyc,f))
365 return qe_invalid;
366
367 if(!p_igetw(&dummyw,f))
368 return qe_invalid;
369
370 if(!p_igetw(&dummyw,f))
371 return qe_invalid;
372
373 if(!p_igetw(&dummyw,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_igetw(&dummyw,f))
386 return qe_invalid;
387
388 if(!p_igetw(&dummyw,f))
389 return qe_invalid;
390
391 if(!p_igetw(&dummyw,f))
392 return qe_invalid;
393
394 if(!p_igetw(&dummyw,f))
395 return qe_invalid;
396
397 if(!p_getc(&dummyc,f))
398 return qe_invalid;
399
400 if(!p_getc(&dummyc,f))
401 return qe_invalid;
402 }
403
404 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
405 {
406 readmapscreen(f, &header, &temp_mapscr, sversion);
407 }
408
409 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
410 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
411
412 pack_fclose(f);
413 clear_quest_tmpfile();
414
415 return true;
416 }
417
418 bool zmap::clearmap(bool newquest)
419 {
420 if(cursor.map<map_count)
421 {
422 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
423 {
424 clearscr(i);
425 }
426
427 setCurrScr(0);
428
429 if(newquest)
430 {
431 if(!reset_templates(false))
432 {
433 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
434 }
435 }
436 }
437
438 return true;
439 }
440
441 MapCursor zmap::getCursor() const
442 {
443 return cursor;
444 }
445
446 void zmap::setCursor(MapCursor new_cursor)
447 {
448 if (cursor == new_cursor)
449 return;
450
451 optional<int> oldcolor;
452 if (screens)
453 oldcolor = getcolor();
454
455 cursor = new_cursor;
456
457 int newcolor = getcolor();
458 loadlvlpal(newcolor);
459 if (!oldcolor || *oldcolor != newcolor)
460 rebuild_trans_table();
461
462 reset_combo_animations2();
463 mmap_mark_dirty();
464 refresh(rALL);
465 }
466
467 bool zmap::isValidPosition(ComboPosition pos) const
468 {
469 return pos.is_valid(cursor);
470 }
471
472 int zmap::getScreenForPosition(ComboPosition pos) const
473 {
474 return cursor.viewscr + pos.screen_offset();
475 }
476
477 mapscr* zmap::CurrScr()
478 {
479 return screens+cursor.screen;
480 }
481 mapscr* zmap::Scr(int32_t scr)
482 {
483 return screens+scr;
484 }
485 mapscr* zmap::Scr(ComboPosition pos)
486 {
487 if (!pos.is_valid(cursor))
488 return nullptr;
489
490 int screen_offset = pos.screen_offset();
491 int screen = cursor.viewscr + screen_offset;
492 return AbsoluteScr(cursor.map, screen);
493 }
494 mapscr* zmap::Scr(ComboPosition pos, int layer)
495 {
496 int map = cursor.map;
497 int screen = cursor.viewscr + pos.screen_offset();
498 if (layer)
499 {
500 mapscr* scr = Map.AbsoluteScr(map, screen);
501 map = scr->layermap[CurrentLayer-1]-1;
502 screen = scr->layerscreen[CurrentLayer-1];
503 }
504
505 return AbsoluteScr(map, screen);
506 }
507 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
508 {
509 mapscr* scr = Scr(pos, layer);
510 if (scr && !(scr->valid&mVALID))
511 {
512 scr->valid |= mVALID;
513 setcolor(Color, scr);
514 }
515 return scr;
516 }
517 mapscr* zmap::AbsoluteScr(int32_t scr)
518 {
519 if(unsigned(scr) >= MAPSCRS*getMapCount())
520 return nullptr;
521 return &TheMaps[scr];
522 }
523 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
524 {
525 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
526 return nullptr;
527 return AbsoluteScr((map*MAPSCRS)+scr);
528 }
529 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
530 {
531 mapscr* scr = AbsoluteScr(map, screen);
532 if (scr && !(scr->valid&mVALID))
533 {
534 scr->valid |= mVALID;
535 setcolor(Color, scr);
536 }
537 return scr;
538 }
539 void zmap::set_prvscr(int32_t map, int32_t scr)
540 {
541 prvscr=TheMaps[(map*MAPSCRS)+scr];
542
543 for(int32_t i=0; i<6; i++)
544 {
545 if(prvscr.layermap[i]>0)
546 {
547 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
548 }
549 else
550 prvlayers[i].valid = 0;
551 }
552
553 prv_map=map;
554 prv_scr=scr;
555 }
556 71 int32_t zmap::getCurrMap()
557 {
558 71 return cursor.map;
559 }
560 bool zmap::isDark(int scr)
561 {
562 return (screens[scr].flags&fDARK)!=0;
563 }
564
565 9 void zmap::setCurrMap(int32_t index)
566 {
567 9 optional<int> oldcolor;
568
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
569 oldcolor = getcolor();
570 9 scrpos[cursor.map] = cursor.screen;
571 9 scrview[cursor.map] = cursor.viewscr;
572 9 cursor.map = bound(index,0,map_count);
573 9 screens = &TheMaps[cursor.map*MAPSCRS];
574
575 9 cursor.viewscr = scrview[cursor.map];
576 9 cursor.setScreen(scrpos[cursor.map]);
577
578 9 int newcolor = getcolor();
579 9 loadlvlpal(newcolor);
580
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
581 9 rebuild_trans_table();
582
583 9 reset_combo_animations2();
584 9 mmap_mark_dirty();
585 9 }
586
587 17 int32_t zmap::getCurrScr()
588 {
589 17 return cursor.screen;
590 }
591 9 void zmap::setCurrScr(int32_t scr)
592 {
593
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (scr == cursor.screen)
594 1 return;
595
596 8 int32_t oldcolor=getcolor();
597 8 cursor.setScreen(scr);
598
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!(screens[cursor.screen].valid&mVALID))
599 {
600 oldcolor=-1;
601 }
602
603 8 int32_t newcolor=getcolor();
604 8 loadlvlpal(newcolor);
605
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (newcolor!=oldcolor)
606 {
607 7 rebuild_trans_table();
608 7 }
609
610 8 reset_combo_animations2();
611 8 setlayertarget();
612 8 mmap_mark_dirty();
613 9 }
614
615 int32_t zmap::getViewScr()
616 {
617 return cursor.viewscr;
618 }
619
620 9 void zmap::setViewSize(int32_t size)
621 {
622 9 cursor.setSize(size);
623 9 }
624
625 6 int32_t zmap::getViewSize()
626 {
627 6 return cursor.size;
628 }
629
630 8 void zmap::setlayertarget()
631 {
632 8 layer_target_map = 0;
633 8 layer_target_multiple = 0;
634
635
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
636 {
637
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
638 {
639 2856 int32_t i=(m*MAPSCRS+s);
640 2856 mapscr *ts=&TheMaps[i];
641
642 // Search through each layer
643
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
644 {
645
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
646 {
647 if(layer_target_map > 0)
648 {
649 layer_target_multiple += 1;
650 continue;
651 }
652
653 layer_target_map = m+1;
654 layer_target_scr = s;
655 }
656 17136 }
657 2856 }
658 21 }
659 8 }
660
661 void zmap::setcolor(int color, mapscr* scr)
662 {
663 if (!scr) scr = CurrScr();
664 scr->valid |= mVALID;
665 scr->color = color;
666
667 if(Color!=color)
668 {
669 Color = color;
670 loadlvlpal(color);
671 rebuild_trans_table();
672 }
673
674 mmap_mark_dirty();
675 }
676
677 25 int32_t zmap::getcolor()
678 {
679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
680 {
681 return prvscr.color;
682 }
683
684 25 return screens[cursor.screen].color;
685 25 }
686
687 void zmap::resetflags()
688 {
689 byte *di=&(screens[cursor.screen].valid);
690
691 for(int32_t i=1; i<48; i++)
692 {
693 *(di+i)=0;
694 }
695 }
696
697 word zmap::tcmbdat(int32_t pos)
698 {
699 return screens[TEMPLATE].data[pos];
700 }
701
702 word zmap::tcmbcset(int32_t pos)
703 {
704 return screens[TEMPLATE].cset[pos];
705 }
706
707 int32_t zmap::tcmbflag(int32_t pos)
708 {
709 return screens[TEMPLATE].sflag[pos];
710 }
711
712 word zmap::tcmbdat2(int32_t pos)
713 {
714 return screens[TEMPLATE2].data[pos];
715 }
716
717 word zmap::tcmbcset2(int32_t pos)
718 {
719 return screens[TEMPLATE2].cset[pos];
720 }
721
722 int32_t zmap::tcmbflag2(int32_t pos)
723 {
724 return screens[TEMPLATE2].sflag[pos];
725 }
726
727 void zmap::TemplateAll()
728 {
729 StartListCommand();
730 for(int32_t i=0; i<128; i++)
731 {
732 if((screens[i].valid&mVALID) && isDungeon(i))
733 DoTemplateCommand(-1, -1, i);
734 }
735 FinishListCommand();
736 }
737
738 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
739 {
740 if(scr==TEMPLATE)
741 return;
742
743 if(!(screens[scr].valid&mVALID))
744 screens[scr].color=Color;
745
746 screens[scr].valid|=mVALID;
747
748 for(int32_t i=0; i<32; i++)
749 {
750 screens[scr].data[i]=screens[TEMPLATE].data[i];
751 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
752 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
753 }
754
755 for(int32_t i=144; i<176; i++)
756 {
757 screens[scr].data[i]=screens[TEMPLATE].data[i];
758 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
759 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
760 }
761
762 for(int32_t y=2; y<=9; y++)
763 {
764 int32_t j=y<<4;
765 screens[scr].data[j]=screens[TEMPLATE].data[j];
766 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
767 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
768 ++j;
769 screens[scr].data[j]=screens[TEMPLATE].data[j];
770 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
771 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
772 ++j;
773 j+=12;
774 screens[scr].data[j]=screens[TEMPLATE].data[j];
775 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
776 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
777 ++j;
778 screens[scr].data[j]=screens[TEMPLATE].data[j];
779 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
780
781 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
782 ++j;
783 }
784
785 if(floorcombo!=-1)
786 {
787 for(int32_t y=2; y<9; y++)
788 for(int32_t x=2; x<14; x++)
789 {
790 int32_t i=(y<<4)+x;
791 screens[scr].data[i] = floorcombo;
792 screens[scr].cset[i] = floorcset;
793 }
794 }
795
796 for(int32_t i=0; i<4; i++)
797 putdoor(scr,i,screens[scr].door[i]);
798 }
799
800
801 void zmap::clearscr(int32_t scr)
802 {
803 screens[scr].zero_memory();
804 screens[scr].valid=mVERSION;
805 for(int q = 0; q < 6; ++q)
806 {
807 auto layer = map_autolayers[cursor.map*6+q];
808 screens[scr].layermap[q] = layer;
809 screens[scr].layerscreen[q] = layer ? scr : 0;
810 }
811 mmap_mark_dirty();
812 }
813
814 const char *loaderror[] =
815 {
816
817 "OK","File not found","Incomplete data",
818 "Invalid version","Invalid file"
819
820 };
821
822 int32_t zmap::load(const char *path)
823 {
824 PACKFILE *f=pack_fopen_password(path,F_READ, "");
825
826 if(!f)
827 return 1;
828
829
830 int16_t version;
831 byte build;
832
833 //get the version
834 if(!p_igetw(&version,f))
835 {
836 goto file_error;
837 }
838
839 //get the build
840 if(!p_getc(&build,f))
841 {
842 goto file_error;
843 }
844
845 for(int32_t i=0; i<MAPSCRS; i++)
846 {
847 mapscr tmpimportscr;
848 tmpimportscr.zero_memory();
849 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
850 {
851 al_trace("failed zmap::load\n");
852 goto file_error;
853 }
854
855 switch(ImportMapBias)
856 {
857 case 0:
858 *(screens+i) = tmpimportscr;
859 break;
860
861 case 1:
862 if(!(screens[i].valid&mVALID))
863 {
864 *(screens+i) = tmpimportscr;
865 }
866 break;
867
868 case 2:
869 if(tmpimportscr.valid&mVALID)
870 {
871 *(screens+i) = tmpimportscr;
872 }
873 break;
874 }
875 }
876
877
878 pack_fclose(f);
879
880 setCurrScr(0);
881 mmap_mark_dirty();
882 return 0;
883
884 file_error:
885 pack_fclose(f);
886 clearmap(false);
887 return 2;
888 }
889
890 int32_t zmap::save(const char *path)
891 {
892 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
893
894 if(!f)
895 return 1;
896
897 if(!p_iputw(V_MAPS,f))
898 {
899 pack_fclose(f);
900 return 3;
901 }
902
903 // This was the "build number", but that's totally useless here. Keep this junk byte
904 // so as not to totally break exports between ZC versions.
905 if(!p_putc(0,f))
906 {
907 pack_fclose(f);
908 return 3;
909 }
910
911 for(int32_t i=0; i<MAPSCRS; i++)
912 {
913 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
914 {
915 pack_fclose(f);
916 return 2;
917 }
918 }
919
920 pack_fclose(f);
921 return 0;
922 }
923
924
925 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
926 {
927 // Hookshots can be blocked by solid combos on all 3 ground layers.
928 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
929
930 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
931 return true;
932 if (c->walk&(1<<i))
933 return false;
934
935 for(int32_t k=0; k<2; k++)
936 {
937 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
938
939 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
940 {
941 return false;
942 }
943 }
944
945 return true;
946 }
947
948 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
949 {
950 // Hookshots can be blocked by solid combos on all 3 ground layers.
951 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
952
953 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
954 return true;
955 if (c->walk&(1<<i))
956 return false;
957
958 for(int32_t k=0; k<2; k++)
959 {
960 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
961
962 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
963 {
964 return false;
965 }
966 }
967
968 return true;
969 }
970
971 bool zmap::isstepable(int32_t combo)
972 {
973 // This is kind of odd but it's true to the engine (see maps.cpp)
974 return (combo_class_buf[combobuf[combo].type].ladder_pass);
975 }
976
977 // Returns the letter of the warp combo.
978 int32_t zmap::warpindex(int32_t combo)
979 {
980 switch(combobuf[combo].type)
981 {
982 case cCAVE:
983 case cPIT:
984 case cSTAIR:
985 case cCAVE2:
986 case cSWIMWARP:
987 case cDIVEWARP:
988 case cSWARPA:
989 return 0;
990
991 case cCAVEB:
992 case cPITB:
993 case cSTAIRB:
994 case cCAVE2B:
995 case cSWIMWARPB:
996 case cDIVEWARPB:
997 case cSWARPB:
998 return 1;
999
1000 case cCAVEC:
1001 case cPITC:
1002 case cSTAIRC:
1003 case cCAVE2C:
1004 case cSWIMWARPC:
1005 case cDIVEWARPC:
1006 case cSWARPC:
1007 return 2;
1008
1009 case cCAVED:
1010 case cPITD:
1011 case cSTAIRD:
1012 case cCAVE2D:
1013 case cSWIMWARPD:
1014 case cDIVEWARPD:
1015 case cSWARPD:
1016 return 3;
1017
1018 case cPITR:
1019 case cSTAIRR:
1020 case cSWARPR:
1021 return 4;
1022 }
1023
1024 return -1;
1025
1026 }
1027
1028 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1029 {
1030 if(top)
1031 line(dest,x,y,x+15,y,c);
1032 rectfill(dest,x,y,x+3,y+15,c);
1033 rectfill(dest,x+12,y,x+15,y+15,c);
1034 rectfill(dest,x+4,y+2,x+11,y+5,c);
1035 rectfill(dest,x+4,y+10,x+11,y+13,c);
1036 }
1037
1038 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1039 {
1040 line(dest,x,y,x+15,y,c);
1041 }
1042
1043 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1044 {
1045 int32_t cx = COMBOX(pos);
1046 int32_t cy = COMBOY(pos);
1047
1048 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1049
1050 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1051
1052 int32_t bridgedetected = 0;
1053
1054 for(int32_t i=0; i<4; i++)
1055 {
1056 int32_t tx=((i&2)<<2)+x;
1057 int32_t ty=((i&1)<<3)+y;
1058 int32_t tx2=((i&2)<<2)+cx;
1059 int32_t ty2=((i&1)<<3)+cy;
1060 for (int32_t m = layer; m <= 1; m++)
1061 {
1062 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1063 {
1064 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1065 {
1066 bridgedetected |= (1<<i);
1067 }
1068 }
1069 else
1070 {
1071 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1072 {
1073 bridgedetected |= (1<<i);
1074 }
1075 }
1076 }
1077 if (bridgedetected & (1<<i))
1078 {
1079 if (i >= 3) break;
1080 else continue;
1081 }
1082 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1083 {
1084 for(int32_t k=0; k<8; k+=2)
1085 for(int32_t j=0; j<8; j+=2)
1086 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1087 }
1088 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1089 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1090
1091 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1092 {
1093 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1094 {
1095 for(int32_t k=0; k<8; k+=2)
1096 for(int32_t j=0; j<8; j+=2)
1097 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1098 }
1099 else
1100 {
1101 int32_t color = COLOR_SOLID;
1102
1103 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1104 color=vc(6);
1105 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1106 color=vc(7);
1107
1108 rectfill(dest,tx,ty,tx+7,ty+7,color);
1109 }
1110 }
1111 }
1112
1113 bridgedetected = 0;
1114 for(int32_t i=0; i<4; i++)
1115 {
1116 int32_t tx2=((i&2)<<2)+cx;
1117 int32_t ty2=((i&1)<<3)+cy;
1118 for (int32_t m = 0; m <= 1; m++)
1119 {
1120 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1121 {
1122 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1123 {
1124 bridgedetected |= (1<<i);
1125 }
1126 }
1127 else
1128 {
1129 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1130 {
1131 bridgedetected |= (1<<i);
1132 }
1133 }
1134 }
1135 }
1136
1137 // Draw damage combos
1138 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1139 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1140 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1141 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1142 || combo_class_buf[c1.type].modify_hp_amount
1143 || combo_class_buf[c2.type].modify_hp_amount;
1144
1145 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1146
1147 if(dmg)
1148 {
1149 if (bridgedetected <= 0)
1150 {
1151 for(int32_t k=0; k<16; k+=2)
1152 for(int32_t j=0; j<16; j+=2)
1153 if(((k+j)/2)%2)
1154 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1155 }
1156 else
1157 {
1158 for(int32_t i=0; i<4; i++)
1159 {
1160 if (!(bridgedetected & (1<<i)))
1161 {
1162 int32_t tx=((i&2)<<2)+x;
1163 int32_t ty=((i&1)<<3)+y;
1164 for(int32_t k=0; k<8; k+=2)
1165 for(int32_t j=0; j<8; j+=2)
1166 if(((k+j)/2)%2)
1167 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1168 }
1169 }
1170 }
1171 }
1172
1173 if(c.type == cSLOPE)
1174 {
1175 slope_info s(c, x, y);
1176 s.draw(dest, 0, 0, COLOR_SLOPE);
1177 }
1178 auto fl0 = MAPFLAG2(-1,cx,cy);
1179 auto fl1 = MAPFLAG2(0,cx,cy);
1180 auto fl2 = MAPFLAG2(1,cx,cy);
1181 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1182 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1183 {
1184 bool top = false;
1185 if(cy)
1186 {
1187 top = true;
1188 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1189 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1190 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1191 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1192 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1193 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1194 {
1195 top = false;
1196 }
1197 }
1198 draw_ladder(dest,x,y,COLOR_LADDER,top);
1199 }
1200 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1201 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1202 {
1203 draw_platform(dest,x,y,COLOR_LADDER);
1204 }
1205 }
1206
1207 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1208 {
1209 int32_t cx = COMBOX(pos);
1210 int32_t cy = COMBOY(pos);
1211
1212 if (screen < 0) return;
1213 if (map < 0) return;
1214
1215 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1216
1217 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1218
1219 int32_t bridgedetected = 0;
1220 for(int32_t i=0; i<4; i++)
1221 {
1222 int32_t tx=((i&2)<<2)+x;
1223 int32_t ty=((i&1)<<3)+y;
1224 int32_t tx2=((i&2)<<2)+cx;
1225 int32_t ty2=((i&1)<<3)+cy;
1226 for (int32_t m = layer; m <= 1; m++)
1227 {
1228 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1229 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1230 {
1231 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1232 {
1233 bridgedetected |= (1<<i);
1234 }
1235 }
1236 else
1237 {
1238 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1239 {
1240 bridgedetected |= (1<<i);
1241 }
1242 }
1243 }
1244 if (bridgedetected & (1<<i))
1245 {
1246 continue;
1247 }
1248 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1249 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1250
1251
1252 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1253 {
1254 for(int32_t k=0; k<8; k+=2)
1255 for(int32_t j=0; j<8; j+=2)
1256 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1257 }
1258 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1259 {
1260 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1261 {
1262 for(int32_t k=0; k<8; k+=2)
1263 for(int32_t j=0; j<8; j+=2)
1264 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1265 }
1266 else
1267 {
1268 int32_t color = COLOR_SOLID;
1269
1270 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1271 color=vc(6);
1272 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1273 color=vc(7);
1274
1275 rectfill(dest,tx,ty,tx+7,ty+7,color);
1276 }
1277 }
1278 }
1279
1280 bridgedetected = 0;
1281 for(int32_t i=0; i<4; i++)
1282 {
1283 int32_t tx2=((i&2)<<2)+cx;
1284 int32_t ty2=((i&1)<<3)+cy;
1285 for (int32_t m = 0; m <= 1; m++)
1286 {
1287 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1288 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1289 {
1290 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1291 {
1292 bridgedetected |= (1<<i);
1293 }
1294 }
1295 else
1296 {
1297 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1298 {
1299 bridgedetected |= (1<<i);
1300 }
1301 }
1302 }
1303 }
1304
1305 // Draw damage combos
1306 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1307 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1308 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1309 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1310 || combo_class_buf[c1.type].modify_hp_amount
1311 || combo_class_buf[c2.type].modify_hp_amount;
1312
1313 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1314
1315 if(dmg)
1316 {
1317 if (bridgedetected <= 0)
1318 {
1319 for(int32_t k=0; k<16; k+=2)
1320 for(int32_t j=0; j<16; j+=2)
1321 if(((k+j)/2)%2)
1322 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1323 }
1324 else
1325 {
1326 for(int32_t i=0; i<4; i++)
1327 {
1328 if (!(bridgedetected & (1<<i)))
1329 {
1330 int32_t tx=((i&2)<<2)+x;
1331 int32_t ty=((i&1)<<3)+y;
1332 for(int32_t k=0; k<8; k+=2)
1333 for(int32_t j=0; j<8; j+=2)
1334 if(((k+j)/2)%2)
1335 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1336 }
1337 }
1338 }
1339 }
1340
1341 if(c.type == cSLOPE)
1342 {
1343 slope_info s(c, x, y);
1344 s.draw(dest, 0, 0, COLOR_SLOPE);
1345 }
1346 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1347 auto fl1 = MAPFLAG3(map,screen,0,pos);
1348 auto fl2 = MAPFLAG3(map,screen,1,pos);
1349 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1350 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1351 {
1352 bool top = false;
1353 if(cy)
1354 {
1355 top = true;
1356 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1357 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1358 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1359 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1360 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1361 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1362 {
1363 top = false;
1364 }
1365 }
1366 draw_ladder(dest,x,y,COLOR_LADDER,top);
1367 }
1368 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1369 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1370 {
1371 draw_platform(dest,x,y,COLOR_LADDER);
1372 }
1373 }
1374
1375 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1376 {
1377 const newcombo& c = combobuf[cmbdat];
1378
1379 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1380
1381 for(int32_t i=0; i<4; i++)
1382 {
1383 int32_t tx=((i&2)<<2)+x;
1384 int32_t ty=((i&1)<<3)+y;
1385
1386 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1387 {
1388 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1389 {
1390 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1391 }
1392 else
1393 {
1394 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1395 }
1396 }
1397
1398
1399 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1400 {
1401 for(int32_t k=0; k<8; k+=2)
1402 for(int32_t j=0; j<8; j+=2)
1403 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1404 }
1405 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1406 {
1407 if(c.type==cLADDERHOOKSHOT)
1408 {
1409 for(int32_t k=0; k<8; k+=2)
1410 for(int32_t j=0; j<8; j+=2)
1411 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1412 }
1413 else
1414 {
1415 int32_t color = COLOR_SOLID;
1416
1417 if(c.type==cLADDERONLY)
1418 color=vc(6);
1419 else if(c.type==cHOOKSHOTONLY)
1420 color=vc(7);
1421
1422 rectfill(dest,tx,ty,tx+7,ty+7,color);
1423 }
1424 }
1425
1426 // Draw damage combos
1427 if(combo_class_buf[c.type].modify_hp_amount != 0)
1428 {
1429 for(int32_t k=0; k<8; k+=2)
1430 for(int32_t j=0; j<8; j+=2)
1431 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1432 }
1433 }
1434
1435 if(c.type == cSLOPE)
1436 {
1437 slope_info s(c, 0, 0);
1438 zfix const& slope = s.slope();
1439
1440 BITMAP* sub = create_bitmap_ex(8,16,16);
1441 clear_bitmap(sub);
1442 s.draw(sub, 0, 0, COLOR_SLOPE);
1443 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1444 destroy_bitmap(sub);
1445 }
1446 if(c.flag == mfSIDEVIEWLADDER)
1447 {
1448 draw_ladder(dest,x,y,COLOR_LADDER);
1449 }
1450 else if(c.flag == mfSIDEVIEWPLATFORM)
1451 {
1452 draw_platform(dest,x,y,COLOR_LADDER);
1453 }
1454 }
1455
1456 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1457 {
1458 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1459 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1460 }
1461 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1462 {
1463
1464 newcombo const& c = combobuf[cmbdat];
1465
1466 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1467 {
1468 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1469 // text_mode(-1);
1470 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1471 if(sflag)
1472 {
1473 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1474 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1475 }
1476
1477 if(c.flag)
1478 {
1479 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1480 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1481 }
1482 }
1483
1484 if(flags&cCSET)
1485 {
1486 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1487 // text_mode(inv?vc(15):vc(0));
1488 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1489 }
1490 else if(flags&cCTYPE)
1491 {
1492 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1493 // text_mode(inv?vc(15):vc(0));
1494 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1495 }
1496 }
1497
1498 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1499 {
1500 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1501
1502 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1503 if(repos)
1504 {
1505 combotile_override_x = x+(8*(scale-1));
1506 combotile_override_y = y+(8*(scale-1));
1507 }
1508 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1509 if(repos) combotile_override_x = combotile_override_y = -1;
1510 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1511 destroy_bitmap(b);
1512 }
1513 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1514 {
1515 static newcombo nilcombo;
1516 nilcombo.tile = 0;
1517
1518 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1519
1520 if(c.tile==0)
1521 {
1522 rectfill(dest,x,y,x+15,y+15,vc(0));
1523 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1524 return;
1525 }
1526
1527 putcombo(dest,x,y,cmbdat,cset);
1528
1529 /* moved to put_walkflags
1530 for(int32_t i=0; i<4; i++) {
1531
1532 int32_t tx=((i&2)<<2)+x;
1533 int32_t ty=((i&1)<<3)+y;
1534 if((flags&cWALK) && (c.walk&(1<<i)))
1535 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1536 }
1537 */
1538
1539 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1540 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1541 {
1542 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1543 // text_mode(-1);
1544 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1545 if(sflag)
1546 {
1547 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1548 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1549 }
1550
1551 if(combobuf[cmbdat].flag)
1552 {
1553 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1554 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1555 }
1556 }
1557
1558 if(flags&cWALK)
1559 {
1560 put_walkflags(dest,x,y,cmbdat,0);
1561 }
1562
1563 if(flags&cCSET)
1564 {
1565 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1566 // text_mode(inv?vc(15):vc(0));
1567 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1568 }
1569 else if(flags&cCTYPE)
1570 {
1571 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1572 // text_mode(inv?vc(15):vc(0));
1573 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1574 }
1575 }
1576 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1577 {
1578 auto blitx = 1 + (slot % 16) * 17;
1579 auto blity = 1 + (slot / 16) * 17;
1580 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1581 }
1582
1583
1584 void copy_mapscr(mapscr *dest, const mapscr *src)
1585 {
1586 if(!dest || !src) return;
1587 *dest = *src;
1588 }
1589
1590 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1591 {
1592 int32_t x=0,y=0;
1593 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1594
1595 switch(side)
1596 {
1597 case up:
1598 case down:
1599 x=((pos&15)<<4)+xofs;
1600 y=(ignorepos?0:(pos&0xF0))+yofs;
1601 break;
1602
1603 case left:
1604 case right:
1605 x=(ignorepos?0:((pos&15)<<4))+xofs;
1606 y=(pos&0xF0)+yofs;
1607 break;
1608 }
1609
1610 switch(type)
1611 {
1612 case dt_lock:
1613 case dt_shut:
1614 case dt_boss:
1615 case dt_bomb:
1616 switch(side)
1617 {
1618 case up:
1619 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1620 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1621 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1622 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1623 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1624 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1625 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1626 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1627 break;
1628
1629 case down:
1630 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1631 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1632 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1633 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1634 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1635 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1636 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1637 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1638 break;
1639
1640 case left:
1641 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1642 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1643 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1644 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1645 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1646 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1647
1648 if(x+16 >= dest->w)
1649 break;
1650
1651 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1653 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1655 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1656 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1657 break;
1658
1659 case right:
1660
1661 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1663 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1665 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1666 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1667
1668 if(x+16 <= 0)
1669 break;
1670
1671 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1673 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1675 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1676 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1677 break;
1678 }
1679
1680 break;
1681
1682 case dt_pass:
1683 case dt_wall:
1684 case dt_walk:
1685 default:
1686 break;
1687 }
1688 }
1689
1690 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1691 {
1692 int32_t x=((pos&15)<<4)+xofs;
1693 int32_t y=(pos&0xF0)+yofs;
1694 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1695
1696
1697 switch(side)
1698 {
1699 case up:
1700 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1701 {
1702 overcombo(dest,x,y,
1703 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1705 }
1706
1707 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1708 {
1709 overcombo(dest,x+16,y,
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1711
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1713 }
1714
1715 break;
1716
1717 case down:
1718 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1719 {
1720 overcombo(dest,x,y,
1721 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1723 }
1724
1725 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1726 {
1727 overcombo(dest,x+16,y,
1728 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1730 }
1731
1732 break;
1733
1734 case left:
1735 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1736 {
1737 overcombo(dest,x,y,
1738 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1740 }
1741
1742 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1743 {
1744 overcombo(dest,x,y+16,
1745 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1747 }
1748
1749 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1750 {
1751 overcombo(dest,x,y+32,
1752 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1754 }
1755
1756 break;
1757
1758 case right:
1759 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1760 {
1761 overcombo(dest,x,y,
1762 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1764 }
1765
1766 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1767 {
1768 overcombo(dest,x,y+16,
1769
1770 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1772 }
1773
1774 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1775 {
1776 overcombo(dest,x,y+32,
1777 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1779 }
1780
1781 break;
1782 }
1783 }
1784
1785 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1786 {
1787 word cmbcheck1, cmbcheck2;
1788 newcombo combocheck1, combocheck2;
1789 combocheck1 = combobuf[0];
1790 combocheck2 = combobuf[0];
1791 combocheck1.walk = 0;
1792 combocheck2.walk = 0;
1793
1794 int32_t layermap, layerscreen;
1795
1796 switch(dir)
1797 {
1798 case up:
1799 {
1800 if(i>15) //not top row of combos
1801 {
1802 return false;
1803 }
1804
1805 if(scr<16) //top row of screens
1806 {
1807 return false;
1808
1809 }
1810
1811 //check main screen
1812 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1813 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1814 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1815 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1816
1817 //check layer 1
1818 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1819
1820 if(layermap>-1 && layermap<map_count)
1821 {
1822 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1823 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1824 if (combobuf[cmbcheck1].type == cBRIDGE)
1825 {
1826 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1827 {
1828 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1829 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1830 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1831 }
1832 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1833 }
1834 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1835 }
1836
1837 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1838
1839 if(layermap>-1 && layermap<map_count)
1840 {
1841 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1842 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1843 if (combobuf[cmbcheck2].type == cBRIDGE)
1844 {
1845 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1846 {
1847 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1848 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1849 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1850 }
1851 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1852 }
1853 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1854 }
1855
1856 //check layer 2
1857 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1858
1859 if(layermap>-1 && layermap<map_count)
1860 {
1861 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1862
1863 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1864 if (combobuf[cmbcheck2].type == cBRIDGE)
1865 {
1866 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1867 {
1868 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1869 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1870 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1871 }
1872 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1873 }
1874 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1875 }
1876
1877 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1878
1879 if(layermap>-1 && layermap<map_count)
1880 {
1881 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1882 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1883 if (combobuf[cmbcheck2].type == cBRIDGE)
1884 {
1885 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1886 {
1887 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1888 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1889 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1890 }
1891 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1892 }
1893 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1894 }
1895
1896 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1897 {
1898 return true;
1899 }
1900
1901 break;
1902 }
1903 case down:
1904 {
1905 if(i<160) //not bottom row of combos
1906 {
1907 return false;
1908 }
1909
1910 if(scr>111) //bottom row of screens
1911 {
1912 return false;
1913 }
1914
1915 //check main screen
1916 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1917 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1918 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1919 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1920
1921
1922 //check layer 1
1923 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1924
1925 if(layermap>-1 && layermap<map_count)
1926 {
1927 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1928 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1929 if (combobuf[cmbcheck1].type == cBRIDGE)
1930 {
1931 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1932 {
1933 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1934 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1935 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1936 }
1937 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1938 }
1939 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1940 }
1941
1942 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1943
1944 if(layermap>-1 && layermap<map_count)
1945 {
1946 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1947 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1948 if (combobuf[cmbcheck2].type == cBRIDGE)
1949 {
1950 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1951 {
1952 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1953 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1954 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1955 }
1956 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1957 }
1958 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1959 }
1960
1961 //check layer 2
1962 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1963
1964 if(layermap>-1 && layermap<map_count)
1965 {
1966 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1967 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1968 if (combobuf[cmbcheck1].type == cBRIDGE)
1969 {
1970 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1971 {
1972 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1973 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1974 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1975 }
1976 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1977 }
1978 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1979 }
1980
1981 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1982
1983 if(layermap>-1 && layermap<map_count)
1984 {
1985 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1986 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1987 if (combobuf[cmbcheck2].type == cBRIDGE)
1988 {
1989 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1990 {
1991 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1992 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1993 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1994 }
1995 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1996 }
1997 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1998 }
1999
2000 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2001 {
2002 return true;
2003 }
2004
2005 break;
2006 }
2007 case left:
2008 {
2009 if((i&0xF)!=0) //not left column of combos
2010 {
2011 return false;
2012 }
2013
2014 if((scr&0xF)==0) //left column of screens
2015 {
2016 return false;
2017 }
2018
2019 //check main screen
2020 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2021 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
2022 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2023 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2024
2025 //check layer 1
2026 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2027
2028 if(layermap>-1 && layermap<map_count)
2029 {
2030 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2031 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2032 if (combobuf[cmbcheck1].type == cBRIDGE)
2033 {
2034 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2035 {
2036 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2037 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2038 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2039 }
2040 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2041 }
2042 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2043 }
2044
2045 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
2046
2047 if(layermap>-1 && layermap<map_count)
2048 {
2049 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
2050 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2051 if (combobuf[cmbcheck2].type == cBRIDGE)
2052 {
2053 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2054 {
2055 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2056 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2057 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2058 }
2059 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2060 }
2061 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2062 }
2063
2064 //check layer 2
2065 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2066
2067 if(layermap>-1 && layermap<map_count)
2068 {
2069 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2070 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2071 if (combobuf[cmbcheck1].type == cBRIDGE)
2072 {
2073 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2074 {
2075 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2076 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2077 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2078 }
2079 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2080 }
2081 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2082 }
2083
2084 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2085
2086 if(layermap>-1 && layermap<map_count)
2087 {
2088 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2089 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2090 if (combobuf[cmbcheck2].type == cBRIDGE)
2091 {
2092 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2093 {
2094 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2095 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2096 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2097 }
2098 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2099 }
2100 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2101 }
2102
2103 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2104 {
2105 return true;
2106 }
2107
2108 break;
2109 }
2110 case right:
2111 {
2112 if((i&0xF)!=15) //not right column of combos
2113 {
2114 return false;
2115 }
2116
2117 if((scr&0xF)==15) //right column of screens
2118 {
2119 return false;
2120 }
2121
2122 //check main screen
2123 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2124 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2125 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2126 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2127
2128 //check layer 1
2129 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2130
2131 if(layermap>-1 && layermap<map_count)
2132 {
2133 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2134 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2135 if (combobuf[cmbcheck1].type == cBRIDGE)
2136 {
2137 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2138 {
2139 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2140 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2141 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2142 }
2143 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2144 }
2145 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2146 }
2147
2148 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2149
2150 if(layermap>-1 && layermap<map_count)
2151 {
2152 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2153 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2154 if (combobuf[cmbcheck2].type == cBRIDGE)
2155 {
2156 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2157 {
2158 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2159 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2160 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2161 }
2162 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2163 }
2164 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2165 }
2166
2167 //check layer 2
2168 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2169
2170 if(layermap>-1 && layermap<map_count)
2171 {
2172 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2173 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2174 if (combobuf[cmbcheck1].type == cBRIDGE)
2175 {
2176 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2177 {
2178 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2179 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2180 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2181 }
2182 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2183 }
2184 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2185 }
2186
2187 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2188
2189 if(layermap>-1 && layermap<map_count)
2190 {
2191 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2192
2193 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2194 if (combobuf[cmbcheck2].type == cBRIDGE)
2195 {
2196 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2197 {
2198 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2199 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2200 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2201 }
2202 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2203 }
2204 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2205 }
2206
2207 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2208 {
2209 return true;
2210 }
2211
2212 break;
2213 }
2214 }
2215
2216 return false;
2217 }
2218
2219 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2220 {
2221 int32_t checkcombo;
2222
2223 if(alignment_arrow_timer>31)
2224 {
2225 if(scr<0)
2226 {
2227 scr=cursor.screen;
2228 }
2229
2230 if((scr<128)) //do the misalignment arrows
2231 {
2232 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2233 {
2234 if(misaligned(cursor.map, scr, checkcombo, up))
2235 {
2236 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2237 }
2238 }
2239
2240 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2241 {
2242 if(misaligned(cursor.map, scr, checkcombo, down))
2243 {
2244 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 }
2246 }
2247
2248 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2249 {
2250 if(misaligned(cursor.map, scr, checkcombo, left))
2251 {
2252 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 }
2254 }
2255
2256 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2257 {
2258 if(misaligned(cursor.map, scr, checkcombo, right))
2259 {
2260 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2261 }
2262 }
2263
2264 int32_t tempalign;
2265
2266 //check top left corner
2267 checkcombo=0;
2268 tempalign=0;
2269 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2270 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2271
2272 switch(tempalign)
2273 {
2274 case 0:
2275 break;
2276
2277 case 1: //up
2278 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2279 break;
2280
2281 case 2: //left
2282 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2283 break;
2284
2285 case 3: //up-left
2286 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2287 break;
2288 }
2289
2290 //check top right corner
2291 checkcombo=15;
2292 tempalign=0;
2293 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2294 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2295
2296 switch(tempalign)
2297 {
2298 case 0:
2299 break;
2300
2301 case 1: //up
2302 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2303 break;
2304
2305 case 2: //right
2306 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2307 break;
2308
2309 case 3: //up-right
2310 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2311 break;
2312 }
2313
2314 //check bottom left corner
2315 checkcombo=160;
2316 tempalign=0;
2317 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2318 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2319
2320 switch(tempalign)
2321 {
2322 case 0:
2323 break;
2324
2325 case 1: //down
2326 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2327 break;
2328
2329 case 2: //left
2330 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2331 break;
2332
2333 case 3: //down-left
2334 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2335 break;
2336 }
2337
2338 //check bottom right corner
2339
2340 checkcombo=175;
2341 tempalign=0;
2342 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2343 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2344
2345 switch(tempalign)
2346 {
2347 case 0:
2348 break;
2349
2350 case 1: //down
2351 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2352 break;
2353
2354 case 2: //right
2355 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2356 break;
2357
2358 case 3: //down-right
2359 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2360 break;
2361 }
2362 }
2363 }
2364 }
2365
2366 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2367 {
2368 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2369 }
2370
2371 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2372 {
2373 if (map < 0 || screen < 0) return 0;
2374
2375 if(pos>175 || pos < 0)
2376 return 0;
2377
2378 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2379
2380 if(m->valid==0) return 0;
2381
2382 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2383
2384 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2385
2386 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2387
2388 if(scr->valid==0) return 0;
2389
2390 return scr->data[pos]; // entire combo code
2391 }
2392
2393 // Takes array index layer num., not actual layer num.
2394 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2395 {
2396 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2397
2398 if(map<0)
2399 map=cursor.map;
2400
2401 if(scr<0)
2402 scr=cursor.screen;
2403
2404 mapscr *screen1;
2405
2406 if(prv_mode)
2407 {
2408 screen1=get_prvscr();
2409 }
2410 else
2411 {
2412 screen1=AbsoluteScr(cursor.map,cursor.screen);
2413 }
2414
2415 int32_t layermap;
2416 layermap=screen1->layermap[lyr]-1;
2417
2418 if(layermap<0 || layermap >= map_count) return 0;
2419
2420 mapscr *layer;
2421
2422 if(prv_mode)
2423 layer = &prvlayers[lyr];
2424 else
2425 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2426
2427 int32_t combo = COMBOPOS(x,y);
2428
2429 if(combo>175 || combo < 0)
2430 return 0;
2431
2432 return layer->data[combo];
2433 }
2434
2435 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2436 {
2437 if(map<0)
2438 map=cursor.map;
2439
2440 if(scr<0)
2441 scr=cursor.screen;
2442
2443 mapscr *screen1;
2444
2445 if(prv_mode)
2446 {
2447 screen1=get_prvscr();
2448 }
2449 else
2450 {
2451 screen1=AbsoluteScr(cursor.map,cursor.screen);
2452 }
2453
2454 x = vbound(x, 0, 16*16);
2455 y = vbound(y, 0, 11*16);
2456 int32_t combo = COMBOPOS(x,y);
2457
2458 if(combo>175 || combo < 0)
2459 return 0;
2460
2461 return screen1->data[combo];
2462 }
2463
2464 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2465 {
2466 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2467 }
2468
2469 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2470 {
2471 if (map < 0 || screen < 0) return 0;
2472
2473 if(pos>175 || pos < 0)
2474 return 0;
2475
2476 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2477
2478 if(m->valid==0) return 0;
2479
2480 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2481
2482 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2483
2484 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2485
2486 if(scr->valid==0) return 0;
2487
2488 return scr->sflag[pos]; // entire combo code
2489 }
2490
2491 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2492 {
2493 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2494
2495 if(map<0)
2496 map=cursor.map;
2497
2498 if(scr<0)
2499 scr=cursor.screen;
2500
2501 mapscr *screen1;
2502
2503 if(prv_mode)
2504 {
2505 screen1=get_prvscr();
2506 }
2507 else
2508 {
2509 screen1=AbsoluteScr(cursor.map,cursor.screen);
2510 }
2511
2512 int32_t layermap;
2513 layermap=screen1->layermap[lyr]-1;
2514
2515 if(layermap<0 || layermap >= map_count) return 0;
2516
2517 mapscr *layer;
2518
2519 if(prv_mode)
2520 layer = &prvlayers[lyr];
2521 else
2522 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2523
2524 int32_t combo = COMBOPOS(x,y);
2525
2526 if(combo>175 || combo < 0)
2527 return 0;
2528
2529 return layer->sflag[combo];
2530 }
2531
2532 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2533 {
2534 if(map<0)
2535 map=cursor.map;
2536
2537 if(scr<0)
2538 scr=cursor.screen;
2539
2540 mapscr *screen1;
2541
2542 if(prv_mode)
2543 {
2544 screen1=get_prvscr();
2545 }
2546 else
2547 {
2548 screen1=AbsoluteScr(cursor.map,cursor.screen);
2549 }
2550
2551 x = vbound(x, 0, 16*16);
2552 y = vbound(y, 0, 11*16);
2553 int32_t combo = COMBOPOS(x,y);
2554
2555 if(combo>175 || combo < 0)
2556 return 0;
2557
2558 return screen1->sflag[combo];
2559 }
2560
2561 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2562 {
2563 mapscr *layers[7];
2564 mapscr *basescr;
2565 if(prv_mode)
2566 {
2567 layers[0] = &prvscr;
2568 basescr = layers[0];
2569 for(auto q = 1; q < 7; ++q)
2570 {
2571 if(prvlayers[q-1].valid)
2572 layers[q] = &(prvlayers[q-1]);
2573 else layers[q] = NULL;
2574 }
2575 }
2576 else
2577 {
2578 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2579 basescr = layers[0];
2580 for(auto q = 1; q < 7; ++q)
2581 {
2582 int32_t lmap = basescr->layermap[q-1]-1;
2583 int32_t lscr = basescr->layerscreen[q-1];
2584 if(lmap < 0)
2585 layers[q] = NULL;
2586 else layers[q] = AbsoluteScr(lmap, lscr);
2587 }
2588 }
2589 for(auto q = 0; q < 7; ++q)
2590 {
2591 if(!layers[q]) continue;
2592 for(auto pos = 0; pos < 176; ++pos)
2593 {
2594 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2595 if(cmb.type == cTORCH)
2596 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2597 }
2598 }
2599 word maxffc = basescr->numFFC();
2600 for(auto q = 0; q < maxffc; ++q)
2601 {
2602 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2603 if(cmb.type == cTORCH)
2604 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2605 }
2606 }
2607
2608 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2609 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2610 {
2611 newcombo const& cmb = combobuf[cid];
2612 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2613 if(dither)
2614 {
2615 if (LayerDitherSz == 0)
2616 return;
2617 BITMAP* buf = create_bitmap_ex(8,16,16);
2618 clear_bitmap(buf);
2619 overcombo(buf,0,0,cid,cset);
2620 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2621 if(over)
2622 {
2623 if(transp)
2624 {
2625 color_map = &trans_table2;
2626 draw_trans_sprite(dest, buf, x, y);
2627 color_map = &trans_table;
2628 }
2629 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2630 }
2631 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2632 destroy_bitmap(buf);
2633 }
2634 else if(over)
2635 {
2636 if(transp)
2637 overcombotranslucent(dest,x,y,cid,cset,0);
2638 else overcombo(dest,x,y,cid,cset);
2639 }
2640 else put_combo(dest,x,y,cid,cset,flags,sflag);
2641 }
2642 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2643 {
2644 if(!md) return;
2645 for (int32_t i = 0; i < 176; i++)
2646 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2647 }
2648 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2649 {
2650 if(!md) return;
2651 for (int32_t i = 0; i < 176; i++)
2652 {
2653 int data = md->data[i];
2654 if(combo_class_buf[combobuf[data].type].overhead)
2655 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2656 }
2657 }
2658 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2659 {
2660 if(!LayerMaskInt[lyr])
2661 return nullptr;
2662 if(lyr == 0)
2663 return basescr;
2664 int layermap = basescr->layermap[lyr-1]-1;
2665
2666 if(layermap>-1 && layermap<map_count)
2667 {
2668 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2669 return &TheMaps[layerscreen];
2670 }
2671 return nullptr;
2672 }
2673 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2674 {
2675 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2676 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2677
2678 if(map<0)
2679 map=cursor.map;
2680
2681 if(scr<0)
2682 scr=cursor.screen;
2683
2684 mapscr *basescr;
2685 mapscr* layers[7] = {nullptr};
2686
2687 if(prv_mode)
2688 {
2689 hl_layer = -1;
2690 basescr=get_prvscr();
2691 }
2692 else
2693 {
2694 basescr=AbsoluteScr(map,scr);
2695 }
2696 layers[0] = _zmap_get_lyr_checked(0,basescr);
2697 for(int lyr = 1; lyr < 7; ++lyr)
2698 {
2699 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2700 : _zmap_get_lyr_checked(lyr,basescr);
2701 }
2702
2703 int32_t layermap, layerscreen;
2704 if(CurrentLayer < 1)
2705 layermap = -1;
2706 else
2707 layermap=basescr->layermap[CurrentLayer-1]-1;
2708
2709 if(!(basescr->valid&mVALID))
2710 {
2711 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2712 rectfill(dest,x,y,x+255,y+175,vc(1));
2713
2714 if(ShowMisalignments)
2715 {
2716 check_alignments(dest,x,y,scr);
2717 }
2718
2719 return;
2720 }
2721
2722 if(LayerMaskInt[0]==0)
2723 {
2724 byte bgfill = 0;
2725 if (LayerDitherBG > -1)
2726 bgfill = vc(LayerDitherBG);
2727 rectfill(dest,x,y,x+255,y+175,bgfill);
2728 }
2729
2730 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2731 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2732
2733 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2734 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2735
2736 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2737
2738 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2739
2740 int num_ffcs = basescr->numFFC();
2741 for(int32_t i=num_ffcs-1; i>=0; i--)
2742 {
2743 if(basescr->ffcs[i].data)
2744 {
2745 if(!(basescr->ffcs[i].flags&ffc_changer))
2746 {
2747 if(!(basescr->ffcs[i].flags&ffc_overlay))
2748 {
2749 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2750 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2751
2752 if(basescr->ffcs[i].flags&ffc_trans)
2753 {
2754 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2755 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2756 }
2757 else
2758 {
2759 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2760 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2761 }
2762 }
2763 }
2764 }
2765 }
2766
2767 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2768 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2769
2770 int32_t doortype[4];
2771
2772 for(int32_t i=0; i<4; i++)
2773 {
2774 switch(basescr->door[i])
2775 {
2776 case dOPEN:
2777 doortype[i]=dt_pass;
2778 break;
2779
2780 case dLOCKED:
2781 doortype[i]=dt_lock;
2782 break;
2783
2784 case d1WAYSHUTTER:
2785 case dSHUTTER:
2786 doortype[i]=dt_shut;
2787 break;
2788
2789 case dBOSS:
2790 doortype[i]=dt_boss;
2791 break;
2792
2793 case dBOMB:
2794 doortype[i]=dt_bomb;
2795 break;
2796 }
2797 }
2798
2799 switch(basescr->door[up])
2800 {
2801 case dBOMB:
2802 over_door(dest,39,up,x,y,false, scr);
2803 [[fallthrough]];
2804 case dOPEN:
2805 case dLOCKED:
2806 case d1WAYSHUTTER:
2807 case dSHUTTER:
2808 case dBOSS:
2809 put_door(dest,7,up,doortype[up],x,y,false,scr);
2810 break;
2811
2812 case dWALK:
2813 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2814 {
2815 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2816 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2817 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2818 }
2819 else
2820
2821 {
2822 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2823 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2824 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2825 }
2826
2827 break;
2828 }
2829
2830 switch(basescr->door[down])
2831 {
2832 case dBOMB:
2833 over_door(dest,135,down,x,y,false,scr);
2834 [[fallthrough]];
2835 case dOPEN:
2836 case dLOCKED:
2837 case d1WAYSHUTTER:
2838 case dSHUTTER:
2839 case dBOSS:
2840 put_door(dest,151,down,doortype[down],x,y,false,scr);
2841 break;
2842
2843 case dWALK:
2844 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2845 {
2846 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2847 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2848 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2849 }
2850 else
2851 {
2852 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2853 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2854 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2855 }
2856
2857 break;
2858 }
2859
2860 switch(basescr->door[left])
2861 {
2862 case dBOMB:
2863 over_door(dest,66,left,x,y,false,scr);
2864 [[fallthrough]];
2865 case dOPEN:
2866 case dLOCKED:
2867 case d1WAYSHUTTER:
2868 case dSHUTTER:
2869 case dBOSS:
2870 put_door(dest,64,left,doortype[left],x,y,false,scr);
2871 break;
2872
2873 case dWALK:
2874 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2875 {
2876 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2877 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2878 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2879 }
2880 else
2881 {
2882 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2883 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2884 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2885 }
2886
2887 break;
2888 }
2889
2890 switch(basescr->door[right])
2891 {
2892
2893 case dBOMB:
2894 over_door(dest,77,right,x,y,false,scr);
2895 [[fallthrough]];
2896 case dOPEN:
2897 case dLOCKED:
2898 case d1WAYSHUTTER:
2899 case dSHUTTER:
2900 case dBOSS:
2901 put_door(dest,78,right,doortype[right],x,y,false,scr);
2902 break;
2903
2904 case dWALK:
2905 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2906 {
2907 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2908 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2909 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2910 }
2911 else
2912 {
2913 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2914 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2915 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2916 }
2917
2918 break;
2919 }
2920
2921 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2922 {
2923 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2924 }
2925
2926 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2927 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2928 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2929
2930 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2931
2932 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2933 {
2934 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2935 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2936 }
2937 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2938
2939 for(int32_t i=num_ffcs-1; i>=0; i--)
2940 {
2941 if(basescr->ffcs[i].data)
2942 {
2943 if(!(basescr->ffcs[i].flags&ffc_changer))
2944 {
2945 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2946 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2947
2948 if(basescr->ffcs[i].flags&ffc_overlay)
2949 {
2950 if(basescr->ffcs[i].flags&ffc_trans)
2951 {
2952 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2953 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2954 }
2955 else
2956 {
2957 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2958 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2959 }
2960 }
2961 }
2962 }
2963 }
2964
2965 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2966
2967 for(int32_t i=num_ffcs-1; i>=0; i--)
2968 if(basescr->ffcs[i].data)
2969 if(basescr->ffcs[i].flags&ffc_changer)
2970 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2971
2972 if(flags&cWALK)
2973 {
2974 if(layers[0])
2975 for(int32_t i=0; i<176; i++)
2976 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2977
2978 for(int32_t k=0; k<2; k++)
2979 {
2980 if(layers[k+1])
2981 for(int32_t i=0; i<176; i++)
2982 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2983 }
2984 for(int32_t i=num_ffcs-1; i>=0; i--)
2985 {
2986 if(auto data = basescr->ffcs[i].data)
2987 {
2988 if(!(basescr->ffcs[i].flags&ffc_changer))
2989 {
2990 newcombo const& cmb = combobuf[data];
2991 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2992 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2993
2994 if(basescr->ffcs[i].flags&ffc_solid)
2995 {
2996 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2997 }
2998
2999 if(cmb.type == cSLOPE)
3000 {
3001 slope_info s(cmb, tx, ty);
3002 s.draw(dest, 0, 0, COLOR_SLOPE);
3003 }
3004 }
3005 }
3006 }
3007 }
3008
3009 if(flags&cFLAGS)
3010 {
3011 if(LayerMaskInt[CurrentLayer]!=0)
3012 {
3013 for(int32_t i=0; i<176; i++)
3014 {
3015 if(CurrentLayer==0)
3016 {
3017 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3018 }
3019 else
3020 {
3021 if(prv_mode)
3022 {
3023 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3024 }
3025 else if(basescr->layermap[CurrentLayer-1] > 0)
3026 {
3027 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3028
3029 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3030 {
3031 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3032 TheMaps[_lscr].data[i],
3033 TheMaps[_lscr].cset[i], flags,
3034 TheMaps[_lscr].sflag[i]);
3035 }
3036 }
3037 }
3038 }
3039 }
3040 }
3041
3042 int32_t dark = basescr->flags&cDARK;
3043
3044 if(dark && !(flags&cNODARK)
3045 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3046 {
3047 for(int32_t j=0; j<80; j++)
3048 {
3049 for(int32_t i=0; i<(80)-j; i++)
3050 {
3051 if(((i^j)&1)==0)
3052 {
3053 putpixel(dest,x+i,y+j,vc(blackout_color));
3054 }
3055 }
3056 }
3057 }
3058
3059 if(ShowMisalignments)
3060 {
3061 check_alignments(dest,x,y,scr);
3062 }
3063 }
3064
3065 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3066 {
3067 if(map<0)
3068 map=cursor.map;
3069
3070 if(scr<0)
3071 scr=cursor.screen;
3072
3073 mapscr* layer=AbsoluteScr(map,scr);
3074 int32_t layermap=0, layerscreen=0;
3075
3076 if(!(layer->valid&mVALID))
3077 {
3078 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3079 rectfill(dest,x,y,x+255,y+15,vc(1));
3080 return;
3081 }
3082
3083 int32_t dark = layer->flags&4;
3084
3085 if(LayerMaskInt[0]==0)
3086 {
3087 rectfill(dest,x,y,x+255,y+15,0);
3088 }
3089
3090
3091 for(int32_t k=1; k<3; k++)
3092 {
3093 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3094 {
3095 layermap=layer->layermap[k]-1;
3096
3097 if(layermap>-1 && layermap<map_count)
3098 {
3099 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3100
3101 for(int32_t i=c; i<(c&0xF0)+16; i++)
3102 {
3103 auto data = TheMaps[layerscreen].data[i];
3104 auto cs = TheMaps[layerscreen].cset[i];
3105 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3106 }
3107 }
3108 }
3109 }
3110
3111 if(LayerMaskInt[0]!=0)
3112 {
3113 for(int32_t i=c; i<(c&0xF0)+16; i++)
3114 {
3115 word cmbdat = (i < 176 ? layer->data[i] : 0);
3116 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3117 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3118 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3119 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3120 }
3121 }
3122
3123 for(int32_t k=0; k<2; k++)
3124 {
3125 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3126 {
3127 layermap=layer->layermap[k]-1;
3128
3129 if(layermap>-1 && layermap<map_count)
3130 {
3131 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3132
3133 for(int32_t i=c; i<(c&0xF0)+16; i++)
3134 {
3135 auto data = TheMaps[layerscreen].data[i];
3136 auto cs = TheMaps[layerscreen].cset[i];
3137 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3138 }
3139 }
3140 }
3141 }
3142
3143 int32_t doortype[4];
3144
3145 for(int32_t i=0; i<4; i++)
3146 {
3147 switch(layer->door[i])
3148 {
3149 case dOPEN:
3150 doortype[i]=dt_pass;
3151 break;
3152
3153 case dLOCKED:
3154 doortype[i]=dt_lock;
3155 break;
3156
3157 case d1WAYSHUTTER:
3158 case dSHUTTER:
3159 doortype[i]=dt_shut;
3160 break;
3161
3162 case dBOSS:
3163 doortype[i]=dt_boss;
3164 break;
3165
3166 case dBOMB:
3167 doortype[i]=dt_bomb;
3168 break;
3169 }
3170 }
3171
3172 if(c<16)
3173 {
3174 switch(layer->door[up])
3175 {
3176 case dBOMB:
3177 case dOPEN:
3178 case dLOCKED:
3179 case d1WAYSHUTTER:
3180 case dSHUTTER:
3181 case dBOSS:
3182 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3183 break;
3184 }
3185 }
3186 else if(c>159)
3187 {
3188 switch(layer->door[down])
3189 {
3190 case dBOMB:
3191 case dOPEN:
3192 case dLOCKED:
3193 case d1WAYSHUTTER:
3194 case dSHUTTER:
3195 case dBOSS:
3196 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3197 break;
3198 }
3199 }
3200
3201 for(int32_t k=2; k<4; k++)
3202 {
3203 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3204 {
3205 layermap=layer->layermap[k]-1;
3206
3207 if(layermap>-1 && layermap<map_count)
3208 {
3209 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3210
3211 for(int32_t i=c; i<(c&0xF0)+16; i++)
3212 {
3213 if(layer->layeropacity[k]<255)
3214 {
3215 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3216 }
3217 else
3218 {
3219 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3220 }
3221 }
3222 }
3223 }
3224 }
3225
3226 //Overhead L0
3227 if(LayerMaskInt[0]!=0)
3228 {
3229 for(int32_t i=c; i<(c&0xF0)+16; i++)
3230 {
3231 int32_t ct1=layer->data[i];
3232 int32_t ct3=combobuf[ct1].type;
3233
3234 if(combo_class_buf[ct3].overhead)
3235 {
3236 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3237 }
3238 }
3239 }
3240
3241 //Overhead L1/2
3242 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3243 {
3244 for(int32_t k = 0; k < 2; ++k)
3245 {
3246 if(LayerMaskInt[k+1]!=0)
3247 {
3248 layermap=layer->layermap[k]-1;
3249
3250 if(layermap>-1 && layermap<map_count)
3251 {
3252 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3253 for(int32_t i=c; i<(c&0xF0)+16; i++)
3254 {
3255 auto data = TheMaps[layerscreen].data[i];
3256 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3257 auto cs = TheMaps[layerscreen].cset[i];
3258 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3259 }
3260 }
3261 }
3262 }
3263 }
3264
3265 for(int32_t k=4; k<6; k++)
3266 {
3267 if(LayerMaskInt[k+1]!=0)
3268 {
3269 layermap=layer->layermap[k]-1;
3270
3271 if(layermap>-1 && layermap<map_count)
3272 {
3273 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3274
3275 for(int32_t i=c; i<(c&0xF0)+16; i++)
3276 {
3277 auto data = TheMaps[layerscreen].data[i];
3278 auto cs = TheMaps[layerscreen].cset[i];
3279 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3280 }
3281 }
3282 }
3283 }
3284
3285 if(flags&cWALK)
3286 {
3287 if(LayerMaskInt[0]!=0)
3288 {
3289 for(int32_t i=c; i<(c&0xF0)+16; i++)
3290 {
3291 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3292 }
3293 }
3294
3295 for(int32_t k=0; k<2; k++)
3296 {
3297 if(LayerMaskInt[k+1]!=0)
3298 {
3299 for(int32_t i=c; i<(c&0xF0)+16; i++)
3300 {
3301 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3302 }
3303 }
3304 }
3305 }
3306
3307 if(flags&cFLAGS)
3308 {
3309 if(LayerMaskInt[CurrentLayer]!=0)
3310 {
3311 for(int32_t i=c; i<(c&0xF0)+16; i++)
3312 {
3313 if(CurrentLayer==0)
3314 {
3315 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3316 }
3317 else
3318 {
3319 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3320
3321 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3322 {
3323 if(i < 176)
3324 {
3325 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3326 TheMaps[_lscr].data[i],
3327 TheMaps[_lscr].cset[i], flags|dark,
3328 TheMaps[_lscr].sflag[i]);
3329 }
3330 else
3331 {
3332 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3333 }
3334 }
3335 }
3336 }
3337 }
3338
3339 /*
3340 if (LayerMaskInt[0]!=0) {
3341 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3342 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3343 }
3344 }
3345 */
3346 }
3347
3348 if(ShowMisalignments)
3349 {
3350 if(c<16)
3351 {
3352 check_alignments(dest,x,y,scr);
3353 }
3354 else if(c>159)
3355 {
3356 check_alignments(dest,x,y-160,scr);
3357 }
3358 }
3359 }
3360
3361 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3362 {
3363 if(map<0)
3364 map=cursor.map;
3365
3366 if(scr<0)
3367 scr=cursor.screen;
3368
3369 mapscr* layer=AbsoluteScr(map,scr);
3370 int32_t layermap=0, layerscreen=0;
3371
3372 if(!(layer->valid&mVALID))
3373 {
3374 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3375 rectfill(dest,x,y,x+15,y+175,vc(1));
3376 return;
3377 }
3378
3379 int32_t dark = layer->flags&4;
3380
3381 if(LayerMaskInt[0]==0)
3382 {
3383 rectfill(dest,x,y,x+15,y+175,0);
3384 }
3385
3386
3387 for(int32_t k=1; k<3; k++)
3388 {
3389 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3390 {
3391 layermap=layer->layermap[k]-1;
3392
3393 if(layermap>-1 && layermap<map_count)
3394 {
3395 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3396
3397 for(int32_t i=c; i<176; i+=16)
3398 {
3399 auto data = TheMaps[layerscreen].data[i];
3400 auto cs = TheMaps[layerscreen].cset[i];
3401 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3402 }
3403 }
3404 }
3405 }
3406
3407 if(LayerMaskInt[0]!=0)
3408 {
3409 for(int32_t i=c; i<176; i+=16)
3410 {
3411 word cmbdat = layer->data[i];
3412 byte cmbcset = layer->cset[i];
3413 int32_t cmbflag = layer->sflag[i];
3414 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3415 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3416 }
3417 }
3418
3419 for(int32_t k=0; k<2; k++)
3420 {
3421 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3422 {
3423 layermap=layer->layermap[k]-1;
3424
3425 if(layermap>-1 && layermap<map_count)
3426 {
3427 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3428
3429 for(int32_t i=c; i<176; i+=16)
3430 {
3431 auto data = TheMaps[layerscreen].data[i];
3432 auto cs = TheMaps[layerscreen].cset[i];
3433 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3434 }
3435 }
3436 }
3437 }
3438
3439 int32_t doortype[4];
3440
3441 for(int32_t i=0; i<4; i++)
3442 {
3443 switch(layer->door[i])
3444 {
3445 case dOPEN:
3446 doortype[i]=dt_pass;
3447 break;
3448
3449 case dLOCKED:
3450 doortype[i]=dt_lock;
3451 break;
3452
3453 case d1WAYSHUTTER:
3454 case dSHUTTER:
3455 doortype[i]=dt_shut;
3456 break;
3457
3458 case dBOSS:
3459 doortype[i]=dt_boss;
3460 break;
3461
3462 case dBOMB:
3463 doortype[i]=dt_bomb;
3464 break;
3465 }
3466 }
3467
3468 if((c&0x0F)==0)
3469 {
3470 switch(layer->door[left])
3471 {
3472
3473 case dBOMB:
3474 case dOPEN:
3475 case dLOCKED:
3476 case d1WAYSHUTTER:
3477 case dSHUTTER:
3478 case dBOSS:
3479 // put_door(dest,64,left,doortype[left],x+256,y,true);
3480 put_door(dest,64,left,doortype[left],x,y,true,scr);
3481 break;
3482 }
3483 }
3484 else if((c&0x0F)==15)
3485 {
3486 switch(layer->door[right])
3487 {
3488 case dBOMB:
3489 case dOPEN:
3490 case dLOCKED:
3491 case d1WAYSHUTTER:
3492 case dSHUTTER:
3493 case dBOSS:
3494 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3495 break;
3496 }
3497 }
3498
3499 for(int32_t k=2; k<4; k++)
3500 {
3501 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3502 {
3503 layermap=layer->layermap[k]-1;
3504
3505 if(layermap>-1 && layermap<map_count)
3506 {
3507 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3508
3509 for(int32_t i=c; i<176; i+=16)
3510 {
3511 auto data = TheMaps[layerscreen].data[i];
3512 auto cs = TheMaps[layerscreen].cset[i];
3513 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3514 }
3515 }
3516 }
3517 }
3518
3519 //Overhead L0
3520 if(LayerMaskInt[0]!=0)
3521 {
3522 for(int32_t i=c; i<176; i+=16)
3523 {
3524 auto data = TheMaps[layerscreen].data[i];
3525 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3526 auto cs = TheMaps[layerscreen].cset[i];
3527 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3528 }
3529 }
3530 //Overhead L1/2
3531 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3532 {
3533 for(int32_t k = 0; k < 2; ++k)
3534 {
3535 if(LayerMaskInt[k+1]!=0)
3536 {
3537 layermap=layer->layermap[k]-1;
3538
3539 if(layermap>-1 && layermap<map_count)
3540 {
3541 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3542 for(int32_t i=c; i<176; i+=16)
3543 {
3544 auto data = TheMaps[layerscreen].data[i];
3545 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3546 auto cs = TheMaps[layerscreen].cset[i];
3547 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3548 }
3549 }
3550 }
3551 }
3552 }
3553
3554
3555 for(int32_t k=4; k<6; k++)
3556 {
3557 if(LayerMaskInt[k+1]!=0)
3558 {
3559 layermap=layer->layermap[k]-1;
3560
3561 if(layermap>-1 && layermap<map_count)
3562 {
3563 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3564
3565 for(int32_t i=c; i<176; i+=16)
3566 {
3567 auto data = TheMaps[layerscreen].data[i];
3568 auto cs = TheMaps[layerscreen].cset[i];
3569 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3570 }
3571 }
3572 }
3573 }
3574
3575 if(flags&cWALK)
3576 {
3577 if(LayerMaskInt[0]!=0)
3578 {
3579 for(int32_t i=c&0xF; i<176; i+=16)
3580 {
3581 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3582 }
3583 }
3584
3585 for(int32_t k=0; k<2; k++)
3586 {
3587 if(LayerMaskInt[k+1]!=0)
3588 {
3589 for(int32_t i=c&0xF; i<176; i+=16)
3590 {
3591 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3592 }
3593 }
3594 }
3595 }
3596
3597 if(flags&cFLAGS)
3598 {
3599 if(LayerMaskInt[CurrentLayer]!=0)
3600 {
3601 for(int32_t i=c; i<176; i+=16)
3602 {
3603 if(CurrentLayer==0)
3604 {
3605 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3606 }
3607 else
3608 {
3609 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3610
3611 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3612 {
3613 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3614 TheMaps[_lscr].data[i],
3615 TheMaps[_lscr].cset[i], flags|dark,
3616 TheMaps[_lscr].sflag[i]);
3617 }
3618 }
3619 }
3620 }
3621 }
3622
3623 if(ShowMisalignments)
3624 {
3625 if((c&0x0F)==0)
3626 {
3627 check_alignments(dest,x,y,scr);
3628 }
3629 else if((c&0x0F)==15)
3630 {
3631 check_alignments(dest,x-240,y,scr);
3632 }
3633 }
3634 }
3635
3636 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3637 {
3638 if(map<0)
3639 map=cursor.map;
3640
3641 if(scr<0)
3642 scr=cursor.screen;
3643
3644 mapscr* layer=AbsoluteScr(map,scr);
3645 int32_t layermap=0, layerscreen=0;
3646
3647 if(!(layer->valid&mVALID))
3648 {
3649 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3650 rectfill(dest,x,y,x+15,y+15,vc(1));
3651 return;
3652 }
3653
3654 int32_t dark = layer->flags&4;
3655
3656 if(LayerMaskInt[0]!=0)
3657 {
3658 rectfill(dest,x,y,x+15,y+15,0);
3659 }
3660
3661 for(int32_t k=1; k<3; k++)
3662 {
3663 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3664 {
3665 layermap=layer->layermap[k]-1;
3666
3667 if(layermap>-1 && layermap<map_count)
3668 {
3669 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3670
3671 auto data = TheMaps[layerscreen].data[c];
3672 auto cs = TheMaps[layerscreen].cset[c];
3673 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3674 }
3675 }
3676 }
3677
3678 if(LayerMaskInt[0]!=0)
3679 {
3680 word cmbdat = layer->data[c];
3681 byte cmbcset = layer->cset[c];
3682 int32_t cmbflag = layer->sflag[c];
3683 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3684 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3685 }
3686
3687
3688 for(int32_t k=0; k<2; k++)
3689 {
3690 if(LayerMaskInt[k+1]!=0)
3691 {
3692 layermap=layer->layermap[k]-1;
3693
3694 if(layermap>-1 && layermap<map_count)
3695 {
3696 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3697
3698 auto data = TheMaps[layerscreen].data[c];
3699 auto cs = TheMaps[layerscreen].cset[c];
3700 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3701 }
3702 }
3703 }
3704
3705 for(int32_t k=2; k<4; k++)
3706 {
3707 if(LayerMaskInt[k+1]!=0)
3708 {
3709 layermap=layer->layermap[k]-1;
3710
3711 if(layermap>-1 && layermap<map_count)
3712 {
3713 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3714 auto data = TheMaps[layerscreen].data[c];
3715 auto cs = TheMaps[layerscreen].cset[c];
3716 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3717 }
3718 }
3719 }
3720
3721 //Overhead L0
3722 if(LayerMaskInt[0]!=0)
3723 {
3724 auto data = TheMaps[layerscreen].data[c];
3725 if(combo_class_buf[combobuf[data].type].overhead)
3726 {
3727 auto cs = TheMaps[layerscreen].cset[c];
3728 drawcombo(dest,x,y,data,cs,0,0);
3729 }
3730 }
3731 //Overhead L1/2
3732 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3733 {
3734 for(int32_t k = 0; k < 2; ++k)
3735 {
3736 if(LayerMaskInt[k+1]!=0)
3737 {
3738 layermap=layer->layermap[k]-1;
3739
3740 if(layermap>-1 && layermap<map_count)
3741 {
3742 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3743 auto data = TheMaps[layerscreen].data[c];
3744 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3745 auto cs = TheMaps[layerscreen].cset[c];
3746 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3747 }
3748 }
3749 }
3750 }
3751
3752
3753 for(int32_t k=4; k<6; k++)
3754 {
3755 if(LayerMaskInt[k+1]!=0)
3756 {
3757 layermap=layer->layermap[k]-1;
3758
3759 if(layermap>-1 && layermap<map_count)
3760 {
3761 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3762 auto data = TheMaps[layerscreen].data[c];
3763 auto cs = TheMaps[layerscreen].cset[c];
3764 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3765 }
3766 }
3767 }
3768
3769 if(flags&cWALK)
3770 {
3771 if(LayerMaskInt[0]!=0)
3772 {
3773 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3774 }
3775
3776 for(int32_t k=0; k<2; k++)
3777 {
3778 if(LayerMaskInt[k+1]!=0)
3779 {
3780 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3781 }
3782 }
3783 }
3784
3785 if(flags&cFLAGS)
3786 {
3787 if(LayerMaskInt[CurrentLayer]!=0)
3788 {
3789 int32_t i = c;
3790 //for(int32_t i=c; i==c; i++)
3791 {
3792 if(CurrentLayer==0)
3793 {
3794 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3795 }
3796 else
3797 {
3798 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3799
3800 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3801 {
3802 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3803 TheMaps[_lscr].data[i],
3804 TheMaps[_lscr].cset[i], flags|dark,
3805 TheMaps[_lscr].sflag[i]);
3806 }
3807 }
3808 }
3809 }
3810 }
3811
3812 if(ShowMisalignments)
3813 {
3814 switch(c)
3815 {
3816 case 0:
3817 check_alignments(dest,x,y,scr);
3818 break;
3819
3820 case 15:
3821 check_alignments(dest,x-240,y,scr);
3822 break;
3823
3824 case 160:
3825 check_alignments(dest,x,y-160,scr);
3826 break;
3827
3828 case 175:
3829 check_alignments(dest,x-240,y-160,scr);
3830 break;
3831 }
3832 }
3833 }
3834
3835 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3836 {
3837 if (InvalidBG == 2)
3838 {
3839 draw_checkerboard(dest, x, y, 16);
3840 }
3841 else if(InvalidBG == 1)
3842 {
3843 for(int32_t dy=0; dy<16; dy++)
3844 {
3845 for(int32_t dx=0; dx<16; dx++)
3846 {
3847 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3848 }
3849 }
3850 }
3851 else
3852 {
3853 rectfill(dest, x, y, x+15, y+15, vc(0));
3854 rect(dest, x, y, x+15, y+15, vc(15));
3855 line(dest, x, y, x+15, y+15, vc(15));
3856 line(dest, x, y+15, x+15, y, vc(15));
3857 }
3858 }
3859
3860 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3861 {
3862 if (InvalidBG == 2)
3863 {
3864 for(int32_t q = 0; q < 11; ++q)
3865 draw_checkerboard(dest, x, y + q * 16, 16);
3866 }
3867 else if(InvalidBG == 1)
3868 {
3869 for(int32_t dy=0; dy<176; dy++)
3870 {
3871 for(int32_t dx=0; dx<16; dx++)
3872 {
3873 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3874 }
3875 }
3876 }
3877 else
3878 {
3879 rectfill(dest, x, y, x+15, y+175, vc(0));
3880 rect(dest, x, y, x+15, y+175, vc(15));
3881 line(dest, x, y, x+15, y+175, vc(15));
3882 line(dest, x, y+175, x+15, y, vc(15));
3883 }
3884 }
3885
3886 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3887 {
3888 if (InvalidBG == 2)
3889 {
3890 for (int32_t q = 0; q < 16; ++q)
3891 draw_checkerboard(dest, x + q * 16, y, 16);
3892 }
3893 else if(InvalidBG == 1)
3894 {
3895 for(int32_t dy=0; dy<16; dy++)
3896 {
3897 for(int32_t dx=0; dx<256; dx++)
3898 {
3899 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3900 }
3901 }
3902 }
3903 else
3904 {
3905 rectfill(dest, x, y, x+255, y+15, vc(0));
3906 rect(dest, x, y, x+255, y+15, vc(15));
3907 line(dest, x, y, x+255, y+15, vc(15));
3908 line(dest, x, y+15, x+255, y, vc(15));
3909 }
3910 }
3911
3912 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3913 {
3914 for(int32_t i=0; i<176; i++)
3915 {
3916 word cmbdat = screens[TEMPLATE].data[i];
3917 byte cmbcset = screens[TEMPLATE].cset[i];
3918 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3919 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3920 }
3921 }
3922
3923 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3924 {
3925 for(int32_t i=0; i<176; i++)
3926 {
3927 word cmbdat = screens[TEMPLATE2].data[i];
3928 byte cmbcset = screens[TEMPLATE2].cset[i];
3929 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3930 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3931 }
3932 }
3933
3934 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3935 {
3936 word cmbdat = screens[TEMPLATE].data[pos];
3937 byte cmbcset = screens[TEMPLATE].cset[pos];
3938 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3939 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3940 }
3941
3942 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3943 {
3944 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3945 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3946 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3947 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3948 }
3949
3950 void zmap::scroll(int32_t dir, bool warp)
3951 {
3952 if(cursor.map<map_count)
3953 {
3954 switch(dir)
3955 {
3956 case up:
3957 if(warp && Map.CurrScr()->flags2&wfUP)
3958 {
3959 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3960 }
3961 else if(cursor.screen>15)
3962 {
3963 setCurrScr(cursor.screen - 16);
3964 }
3965
3966 break;
3967
3968 case down:
3969 if(warp && Map.CurrScr()->flags2&wfDOWN)
3970 {
3971 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3972 }
3973 else if(cursor.screen<MAPSCRS-16)
3974 {
3975 setCurrScr(cursor.screen + 16);
3976 }
3977
3978 break;
3979
3980 case left:
3981 if(warp && Map.CurrScr()->flags2&wfLEFT)
3982 {
3983 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3984 }
3985 else if(cursor.screen&15)
3986 {
3987 setCurrScr(cursor.screen - 1);
3988 }
3989
3990 break;
3991
3992 case right:
3993 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3994 {
3995 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3996 }
3997 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3998 {
3999 setCurrScr(cursor.screen + 1);
4000 }
4001
4002 break;
4003 }
4004 }
4005 }
4006
4007 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
4008 {
4009 switch(side)
4010 {
4011 case up:
4012 switch(door)
4013 {
4014 case dWALL:
4015 case dBOMB:
4016 case dWALK:
4017 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4018 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4019 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4020 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4021 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4022 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4023 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4024 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4025 break;
4026
4027 default:
4028 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4029 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4030 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4031 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4032 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4033 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4034 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4035 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4036 break;
4037 }
4038
4039 break;
4040
4041 case down:
4042 switch(door)
4043 {
4044 case dWALL:
4045 case dBOMB:
4046 case dWALK:
4047 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4048 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4049 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4050 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4051 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4052 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4053 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4054 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4055 break;
4056
4057 default:
4058 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4059 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4060 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4061 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4062 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4063 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4064 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4065 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4066 break;
4067 }
4068
4069 break;
4070
4071 case left:
4072 switch(door)
4073 {
4074 case dWALL:
4075 case dBOMB:
4076 case dWALK:
4077 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4078 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4079 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4080 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4081 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4082 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4083 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4084 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4085 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4086 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4087 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4088 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4089 break;
4090
4091 default:
4092 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4093 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4094 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4095 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4096 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4097 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4098 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4099 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4100 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4101 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4102 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4103 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4104 break;
4105 }
4106
4107 break;
4108
4109 case right:
4110 switch(door)
4111 {
4112 case dWALL:
4113 case dBOMB:
4114 case dWALK:
4115 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4116 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4117 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4118 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4119 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4120 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4121 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4122 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4123 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4124 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4125 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4126 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4127 break;
4128
4129 default:
4130 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4131 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4132 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4133 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4134 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4135 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4136 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4137 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4138 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4139 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4140 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4141 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4142 break;
4143 }
4144
4145 break;
4146 }
4147 }
4148 void zmap::DoPutDoorCommand(int side, int door, bool force)
4149 {
4150 if(!force && screens[cursor.screen].door[side] == door)
4151 return;
4152 bool already_list = InListCommand();
4153 if(!already_list)
4154 StartListCommand();
4155 DoSetDoorCommand(cursor.screen,side,door);
4156 if(door != dNONE)
4157 {
4158 word data[176] = {0};
4159 byte cset[176] = {0};
4160 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4161 for(int q = 0; q < 176; ++q)
4162 if(data[q])
4163 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4164 }
4165 if(!already_list)
4166 FinishListCommand();
4167 }
4168 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4169 {
4170 if(screens[scr].door[side] == door)
4171 return;
4172 screens[scr].door[side] = door;
4173 if(door != dNONE)
4174 {
4175 word data[176] = {0};
4176 byte cset[176] = {0};
4177 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4178 for(int q = 0; q < 176; ++q)
4179 if(data[q])
4180 {
4181 screens[scr].data[q] = data[q];
4182 screens[scr].cset[q] = cset[q];
4183 }
4184 }
4185 }
4186
4187 void list_command::execute()
4188 {
4189 for (auto command : commands)
4190 {
4191 command->execute();
4192 }
4193 }
4194
4195 void list_command::undo()
4196 {
4197 for (int i = commands.size() - 1; i >= 0; i--)
4198 {
4199 commands[i]->undo();
4200 }
4201 }
4202
4203 int list_command::size()
4204 {
4205 int s = 0;
4206 for (auto command : commands)
4207 {
4208 s += command->size();
4209 }
4210 return s;
4211 }
4212
4213 void set_combo_command::execute()
4214 {
4215 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4216 if (!scr_ptr) return;
4217
4218 if (combo != -1) scr_ptr->data[pos] = combo;
4219 scr_ptr->cset[pos] = cset;
4220 }
4221
4222 void set_combo_command::undo()
4223 {
4224 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4225 if(!mapscr_ptr) return;
4226 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4227 mapscr_ptr->cset[pos] = prev_cset;
4228 }
4229
4230 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4231 {
4232 std::array<int, 8> initd_arr;
4233 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4234
4235 return {
4236 .x = ffc.x,
4237 .y = ffc.y,
4238 .vx = ffc.vx,
4239 .vy = ffc.vy,
4240 .ax = ffc.ax,
4241 .ay = ffc.ay,
4242 .data = ffc.data,
4243 .cset = ffc.cset,
4244 .delay = ffc.delay,
4245 .link = ffc.link,
4246 .script = ffc.script,
4247 .tw = ffc.txsz,
4248 .th = ffc.tysz,
4249 .ew = ffc.hit_width,
4250 .eh = ffc.hit_height,
4251 .flags = ffc.flags,
4252 .initd = initd_arr,
4253 };
4254 }
4255
4256 void set_ffc_command::execute()
4257 {
4258 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4259 if(!mapscr_ptr) return;
4260
4261 mapscr_ptr->valid |= mVALID;
4262 mapscr_ptr->ffcs[i].x = data.x;
4263 mapscr_ptr->ffcs[i].y = data.y;
4264 mapscr_ptr->ffcs[i].vx = data.vx;
4265 mapscr_ptr->ffcs[i].vy = data.vy;
4266 mapscr_ptr->ffcs[i].ax = data.ax;
4267 mapscr_ptr->ffcs[i].ay = data.ay;
4268 mapscr_ptr->ffcs[i].data = data.data;
4269 mapscr_ptr->ffcs[i].cset = data.cset;
4270 mapscr_ptr->ffcs[i].delay = data.delay;
4271 mapscr_ptr->ffcs[i].link = data.link;
4272 mapscr_ptr->ffcs[i].script = data.script;
4273 mapscr_ptr->ffcs[i].flags = data.flags;
4274 mapscr_ptr->ffEffectWidth(i, data.ew);
4275 mapscr_ptr->ffEffectHeight(i, data.eh);
4276 mapscr_ptr->ffTileWidth(i, data.tw);
4277 mapscr_ptr->ffTileHeight(i, data.th);
4278 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4279 mapscr_ptr->ffcCountMarkDirty();
4280 mapscr_ptr->ffcs[i].updateSolid();
4281 }
4282
4283 void set_ffc_command::undo()
4284 {
4285 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4286 if(!mapscr_ptr) return;
4287
4288 mapscr_ptr->ffcs[i].x = prev_data.x;
4289 mapscr_ptr->ffcs[i].y = prev_data.y;
4290 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4291 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4292 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4293 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4294 mapscr_ptr->ffcs[i].data = prev_data.data;
4295 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4296 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4297 mapscr_ptr->ffcs[i].link = prev_data.link;
4298 mapscr_ptr->ffcs[i].script = prev_data.script;
4299 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4300 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4301 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4302 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4303 mapscr_ptr->ffTileHeight(i, prev_data.th);
4304 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4305 mapscr_ptr->ffcCountMarkDirty();
4306 mapscr_ptr->ffcs[i].updateSolid();
4307 }
4308
4309 void set_flag_command::execute()
4310 {
4311 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4312 if(!mapscr_ptr) return;
4313
4314 mapscr_ptr->valid |= mVALID;
4315 mapscr_ptr->sflag[pos] = flag;
4316 }
4317
4318 void set_flag_command::undo()
4319 {
4320 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4321 if(!mapscr_ptr) return;
4322 mapscr_ptr->sflag[pos] = prev_flag;
4323 }
4324
4325 void set_door_command::execute()
4326 {
4327 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4328 if(!mapscr_ptr) return;
4329
4330 mapscr_ptr->valid |= mVALID;
4331 mapscr_ptr->door[side] = door;
4332 }
4333
4334 void set_door_command::undo()
4335 {
4336 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4337 }
4338
4339 void set_dcs_command::execute()
4340 {
4341 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4342 if(!mapscr_ptr) return;
4343
4344 mapscr_ptr->valid |= mVALID;
4345 mapscr_ptr->door_combo_set = dcs;
4346 }
4347
4348 void set_dcs_command::undo()
4349 {
4350 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4351 }
4352
4353 void paste_screen_command::execute()
4354 {
4355 perform(screen.get());
4356 }
4357
4358 void paste_screen_command::undo()
4359 {
4360 if (prev_screens.size() > 1)
4361 {
4362 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4363 ASSERT(prev_screens.size() == 128);
4364 for (int i = 0; i < 128; i++)
4365 {
4366 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4367 // TODO: why not just this?
4368 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4369 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4370 }
4371 return;
4372 }
4373
4374 perform(prev_screens[0].get());
4375 }
4376
4377 int paste_screen_command::size()
4378 {
4379 return prev_screens.size() + 1;
4380 }
4381
4382 void paste_screen_command::perform(mapscr* to)
4383 {
4384 if (to)
4385 {
4386 switch (type) {
4387 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4388 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4389 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4390 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4391 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4392 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4393 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4394 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4395 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4396 case ScreenPartial: Map.Paste(*to, screen_index); break;
4397 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4398 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4399 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4400 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4401 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4402 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4403 }
4404 }
4405 else
4406 {
4407 Map.clearscr(screen_index);
4408 }
4409 refresh(rALL);
4410 }
4411
4412 void set_screen_command::execute()
4413 {
4414 if (screen)
4415 {
4416 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4417 }
4418 else
4419 {
4420 Map.clearscr(screen_index);
4421 }
4422 refresh(rALL);
4423 }
4424
4425 void set_screen_command::undo()
4426 {
4427 if (prev_screen)
4428 {
4429 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4430 }
4431 else
4432 {
4433 Map.clearscr(screen_index);
4434 }
4435 refresh(rALL);
4436 }
4437
4438 int set_screen_command::size()
4439 {
4440 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4441 }
4442
4443 static std::shared_ptr<list_command> current_list_command;
4444 void zmap::StartListCommand()
4445 {
4446 ASSERT(!current_list_command);
4447 current_list_command.reset(new list_command);
4448 }
4449
4450 void zmap::FinishListCommand()
4451 {
4452 if (current_list_command->commands.size() == 1)
4453 {
4454 undo_stack.push_back(current_list_command->commands[0]);
4455 }
4456 else if (current_list_command->commands.size() > 1)
4457 {
4458 undo_stack.push_back(current_list_command);
4459 }
4460 CapCommandHistory();
4461 current_list_command = nullptr;
4462 }
4463
4464 void zmap::RevokeListCommand()
4465 {
4466 current_list_command->undo();
4467 current_list_command = nullptr;
4468 }
4469
4470 bool zmap::InListCommand() const
4471 {
4472 return current_list_command ? true : false;
4473 }
4474
4475 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4476 {
4477 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4478 if (!skip_execute) command->execute();
4479 if (current_list_command)
4480 {
4481 current_list_command->commands.push_back(command);
4482 if (current_list_command->commands.size() == 1)
4483 {
4484 current_list_command->cursor = command->cursor;
4485 }
4486 }
4487 else
4488 {
4489 undo_stack.push_back(command);
4490 CapCommandHistory();
4491 }
4492 saved = false;
4493 }
4494
4495 void zmap::UndoCommand()
4496 {
4497 if (undo_stack.size() <= 0) return;
4498
4499 // If not currently looking at the associated screen, first change the view
4500 // and wait for the next call to actually undo this command.
4501 auto command = undo_stack.back();
4502 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4503 {
4504 setCursor(command.get()->cursor);
4505 return;
4506 }
4507
4508 command->undo();
4509 redo_stack.push(command);
4510 undo_stack.pop_back();
4511 saved = false;
4512 }
4513
4514 void zmap::RedoCommand()
4515 {
4516 if (redo_stack.size() <= 0) return;
4517
4518 // If not currently selected the associated screen, first change the cursor
4519 // and wait for the next call to actually execute this command.
4520 auto command = redo_stack.top();
4521 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4522 {
4523 setCursor(command.get()->cursor);
4524 return;
4525 }
4526
4527 command->execute();
4528 undo_stack.push_back(command);
4529 redo_stack.pop();
4530 saved = false;
4531 }
4532
4533 9 void zmap::ClearCommandHistory()
4534 {
4535 9 current_list_command = nullptr;
4536 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4537 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4538 9 }
4539
4540 // Extra amount is from mapscr's vectors.
4541 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4542 // Allow the undo system to use roughly 100 MB of memory.
4543 // This doesn't count the memory used by commands that don't store a mapscr,
4544 // but that should be negligible.
4545 9 static int max_command_size = 100e6 / size_of_mapscr;
4546 void zmap::CapCommandHistory()
4547 {
4548 int size;
4549 do
4550 {
4551 size = 0;
4552 for (auto command : undo_stack)
4553 {
4554 size += command->size();
4555 }
4556 if (size > max_command_size) undo_stack.pop_front();
4557 } while (size > max_command_size);
4558 }
4559
4560 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4561 {
4562 if (!pos.is_valid(cursor))
4563 return;
4564
4565 int map = cursor.map;
4566 int screen = cursor.viewscr + pos.screen_offset();
4567 if (!AbsoluteScr(map, screen))
4568 return;
4569
4570 if (CurrentLayer)
4571 {
4572 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4573 map = scr->layermap[CurrentLayer-1]-1;
4574 screen = scr->layerscreen[CurrentLayer-1];
4575 }
4576 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4577 }
4578
4579 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4580 {
4581 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4582 if (!mapscr_ptr) return;
4583
4584 std::shared_ptr<set_combo_command> command(new set_combo_command);
4585 command->cursor = cursor;
4586 command->map = map;
4587 command->scr = scr;
4588 command->pos = pos;
4589 command->combo = combo;
4590 command->cset = cset;
4591 command->prev_combo = mapscr_ptr->data[pos];
4592 command->prev_cset = mapscr_ptr->cset[pos];
4593 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4594 {
4595 // nothing to do...
4596 return;
4597 }
4598
4599 ExecuteCommand(command);
4600 }
4601
4602 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4603 {
4604 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4605 if(!mapscr_ptr) return;
4606
4607 mapscr_ptr->ensureFFC(i);
4608
4609 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4610
4611 std::array<int, 8> initd_arr;
4612 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4613
4614 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4615
4616 command->cursor = cursor;
4617 command->map = map;
4618 command->scr = scr;
4619 command->i = i;
4620 command->data = data;
4621 command->prev_data = prev_data;
4622 if (data == prev_data)
4623 {
4624 // nothing to do...
4625 return;
4626 }
4627
4628 ExecuteCommand(command);
4629 }
4630
4631 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4632 {
4633 if (!pos.is_valid(cursor))
4634 return;
4635
4636 int map = cursor.map;
4637 int screen = cursor.viewscr + pos.screen_offset();
4638 if (!AbsoluteScr(map, screen))
4639 return;
4640
4641 if (CurrentLayer)
4642 {
4643 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4644 map = scr->layermap[CurrentLayer-1]-1;
4645 screen = scr->layerscreen[CurrentLayer-1];
4646 }
4647 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4648 }
4649
4650 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4651 {
4652 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4653 if(!mapscr_ptr) return;
4654
4655 std::shared_ptr<set_flag_command> command(new set_flag_command);
4656 command->cursor = cursor;
4657 command->map = map;
4658 command->scr = scr;
4659 command->pos = pos;
4660 command->flag = flag;
4661 command->prev_flag = mapscr_ptr->sflag[pos];
4662 if (command->flag == command->prev_flag)
4663 {
4664 // nothing to do...
4665 return;
4666 }
4667
4668 ExecuteCommand(command);
4669 }
4670
4671 void zmap::DoSetDoorCommand(int scr, int side, int door)
4672 {
4673 if(screens[scr].door[side] == door)
4674 return;
4675 std::shared_ptr<set_door_command> command(new set_door_command);
4676 command->cursor = cursor;
4677 command->side = side;
4678 command->door = door;
4679 command->prev_door = screens[scr].door[side];
4680
4681 ExecuteCommand(command);
4682 }
4683 void zmap::DoSetDCSCommand(int dcs)
4684 {
4685 if(screens[cursor.screen].door_combo_set == dcs)
4686 return;
4687 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4688 command->cursor = cursor;
4689 command->dcs = dcs;
4690 command->prev_dcs = screens[cursor.screen].door_combo_set;
4691
4692 ExecuteCommand(command);
4693 }
4694
4695 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4696 {
4697 if (screen == -1)
4698 screen = cursor.screen;
4699
4700 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4701 command->cursor = cursor;
4702 command->type = type;
4703 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4704 command->screen_index = screen;
4705
4706 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4707 {
4708 for (int i=0; i < 128; i++)
4709 {
4710 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4711 }
4712 }
4713 else
4714 {
4715 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4716 }
4717
4718 ExecuteCommand(command);
4719 }
4720
4721 void zmap::DoClearScreenCommand(int screen)
4722 {
4723 std::shared_ptr<set_screen_command> command(new set_screen_command);
4724 command->cursor = cursor;
4725 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4726 command->screen = std::shared_ptr<mapscr>(nullptr);
4727 command->screen_index = screen;
4728
4729 ExecuteCommand(command);
4730 }
4731
4732 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4733 {
4734 std::shared_ptr<set_screen_command> command(new set_screen_command);
4735 command->cursor = cursor;
4736 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4737 Template(floorcombo, floorcset, screen);
4738 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4739
4740 ExecuteCommand(command, true);
4741 }
4742
4743 void zmap::Copy(int scr)
4744 {
4745 if(screens[scr].valid&mVALID)
4746 {
4747 copy_mapscr(&copymapscr, &screens[scr]);
4748 //copymapscr=screens[scr];
4749 can_paste=true;
4750 copymap=cursor.map;
4751 copyscr=scr;
4752 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4753 copyffc = -1;
4754 }
4755 }
4756
4757 void zmap::CopyFFC(int32_t screen, int32_t n)
4758 {
4759 if(screens[screen].valid&mVALID)
4760 {
4761 copy_mapscr(&copymapscr, &screens[screen]);
4762 // Can't paste the screen itself
4763 can_paste = false;
4764 copymap=cursor.map;
4765 copyscr=screen;
4766 copyffc = n;
4767 }
4768 }
4769
4770 void zmap::Paste(const mapscr& copymapscr, int screen)
4771 {
4772 if(can_paste)
4773 {
4774 int32_t oldcolor=getcolor();
4775
4776 if(!(screens[screen].valid&mVALID))
4777 {
4778 screens[screen].valid |= mVALID;
4779 screens[screen].color = copymapscr.color;
4780 }
4781
4782 screens[screen].door_combo_set = copymapscr.door_combo_set;
4783
4784 for(int32_t i=0; i<4; i++)
4785 {
4786 screens[screen].door[i]=copymapscr.door[i];
4787 }
4788
4789 for(int32_t i=0; i<176; i++)
4790 {
4791 screens[screen].data[i] = copymapscr.data[i];
4792 screens[screen].cset[i] = copymapscr.cset[i];
4793 screens[screen].sflag[i] = copymapscr.sflag[i];
4794 }
4795
4796 int32_t newcolor=getcolor();
4797 loadlvlpal(newcolor);
4798
4799 if(newcolor!=oldcolor)
4800 {
4801 rebuild_trans_table();
4802 }
4803
4804 saved=false;
4805 }
4806 }
4807
4808 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4809 {
4810 if(can_paste)
4811 {
4812 screens[screen].undercombo = copymapscr.undercombo;
4813 screens[screen].undercset = copymapscr.undercset;
4814 saved=false;
4815 }
4816 }
4817
4818 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4819 {
4820 if(can_paste)
4821 {
4822 for(int32_t i=0; i<128; i++)
4823 {
4824 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4825 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4826 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4827 }
4828
4829 saved=false;
4830 }
4831 }
4832
4833 // TODO const mapscr& copymapscr
4834 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4835 {
4836 if(can_paste)
4837 {
4838 screens[screen].ffcs = copymapscr.ffcs;
4839 screens[screen].ffcCountMarkDirty();
4840 saved=false;
4841 }
4842 }
4843
4844 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4845 {
4846 if(can_paste)
4847 {
4848 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4849
4850 for(int32_t i=0; i<4; i++)
4851 {
4852 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4853 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4854 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4855 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4856 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4857 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4858 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4859 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4860 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4861 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4862 }
4863
4864 saved=false;
4865 }
4866 }
4867
4868 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4869 {
4870 if(can_paste)
4871 {
4872 screens[screen].csensitive = copymapscr.csensitive;
4873 screens[screen].oceansfx = copymapscr.oceansfx;
4874 screens[screen].bosssfx = copymapscr.bosssfx;
4875 screens[screen].secretsfx = copymapscr.secretsfx;
4876 screens[screen].holdupsfx = copymapscr.holdupsfx;
4877 screens[screen].flags = copymapscr.flags;
4878 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4879 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4880 screens[screen].flags3 = copymapscr.flags3;
4881 screens[screen].flags4 = copymapscr.flags4;
4882 screens[screen].flags5 = copymapscr.flags5;
4883 screens[screen].flags6 = copymapscr.flags6;
4884 screens[screen].flags7 = copymapscr.flags7;
4885 screens[screen].flags8 = copymapscr.flags8;
4886 screens[screen].flags9 = copymapscr.flags9;
4887 screens[screen].flags10 = copymapscr.flags10;
4888 screens[screen].item = copymapscr.item;
4889 screens[screen].hasitem = copymapscr.hasitem;
4890 screens[screen].itemx = copymapscr.itemx;
4891 screens[screen].itemy = copymapscr.itemy;
4892 screens[screen].nextmap = copymapscr.nextmap;
4893 screens[screen].nextscr = copymapscr.nextscr;
4894 screens[screen].nocarry = copymapscr.nocarry;
4895 screens[screen].noreset = copymapscr.noreset;
4896 screens[screen].path[0] = copymapscr.path[0];
4897 screens[screen].path[1] = copymapscr.path[1];
4898 screens[screen].path[2] = copymapscr.path[2];
4899 screens[screen].path[3] = copymapscr.path[3];
4900 screens[screen].pattern = copymapscr.pattern;
4901 screens[screen].exitdir = copymapscr.exitdir;
4902 screens[screen].enemyflags = copymapscr.enemyflags;
4903 screens[screen].screen_midi = copymapscr.screen_midi;
4904 screens[screen].stairx = copymapscr.stairx;
4905 screens[screen].stairy = copymapscr.stairy;
4906 screens[screen].timedwarptics = copymapscr.timedwarptics;
4907 saved=false;
4908 }
4909 }
4910
4911 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4912 {
4913 if(can_paste)
4914 {
4915 screens[screen].warpreturnc = copymapscr.warpreturnc;
4916 screens[screen].warparrivalx = copymapscr.warparrivalx;
4917 screens[screen].warparrivaly = copymapscr.warparrivaly;
4918
4919 for(int32_t i=0; i<4; i++)
4920 {
4921 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4922 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4923 }
4924
4925 saved=false;
4926 }
4927 }
4928
4929 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4930 {
4931 if(can_paste)
4932 {
4933 for(int32_t i=0; i<4; i++)
4934 screens[screen].door[i] = copymapscr.door[i];
4935
4936 screens[screen].door_combo_set = copymapscr.door_combo_set;
4937 saved=false;
4938 }
4939 }
4940
4941 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4942 {
4943 if(can_paste)
4944 {
4945 for(int32_t i=0; i<6; i++)
4946 {
4947 screens[screen].layermap[i] = copymapscr.layermap[i];
4948 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4949 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4950 }
4951
4952 saved=false;
4953 }
4954 }
4955
4956 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4957 {
4958 if(can_paste)
4959 {
4960 screens[screen].room = copymapscr.room;
4961 screens[screen].catchall = copymapscr.catchall;
4962 saved=false;
4963 }
4964 }
4965
4966 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4967 {
4968 if(can_paste)
4969 {
4970 screens[screen].guy = copymapscr.guy;
4971 screens[screen].guytile = copymapscr.guytile;
4972 screens[screen].guycs = copymapscr.guycs;
4973 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4974 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4975 screens[screen].str = copymapscr.str;
4976 saved=false;
4977 }
4978 }
4979
4980 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4981 {
4982 if(can_paste)
4983 {
4984 int32_t oldcolor=getcolor();
4985 screens[screen].color = copymapscr.color;
4986 int32_t newcolor=getcolor();
4987 loadlvlpal(newcolor);
4988
4989 screens[screen].valid|=mVALID;
4990
4991 if(newcolor!=oldcolor)
4992 {
4993 rebuild_trans_table();
4994 }
4995
4996 saved=false;
4997 }
4998 }
4999
5000 void zmap::PasteAll(const mapscr& copymapscr, int screen)
5001 {
5002 if(can_paste)
5003 {
5004 int32_t oldcolor=getcolor();
5005 copy_mapscr(&screens[screen], &copymapscr);
5006 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
5007 //screens[screen]=copymapscr;
5008 int32_t newcolor=getcolor();
5009 loadlvlpal(newcolor);
5010
5011 screens[screen].valid|=mVALID;
5012
5013 if(newcolor!=oldcolor)
5014 {
5015 rebuild_trans_table();
5016 }
5017
5018 saved=false;
5019 }
5020 }
5021
5022
5023 void zmap::PasteToAll(const mapscr& copymapscr)
5024 {
5025 if(can_paste)
5026 {
5027 int32_t oldcolor=getcolor();
5028
5029 for(int32_t x=0; x<128; x++)
5030 {
5031 if(!(screens[x].valid&mVALID))
5032 {
5033 screens[x].valid |= mVALID;
5034 screens[x].color = copymapscr.color;
5035 }
5036
5037 for(int32_t i=0; i<176; i++)
5038 {
5039 screens[x].data[i] = copymapscr.data[i];
5040 screens[x].cset[i] = copymapscr.cset[i];
5041 screens[x].sflag[i] = copymapscr.sflag[i];
5042 }
5043 }
5044
5045 int32_t newcolor=getcolor();
5046 loadlvlpal(newcolor);
5047
5048 if(!(screens[cursor.screen].valid&mVALID))
5049 {
5050 newcolor=-1;
5051 }
5052
5053 if(newcolor!=oldcolor)
5054 {
5055 rebuild_trans_table();
5056 }
5057
5058 saved=false;
5059 }
5060 }
5061
5062 void zmap::PasteAllToAll(const mapscr& copymapscr)
5063 {
5064 if(can_paste)
5065 {
5066 int32_t oldcolor=getcolor();
5067
5068 for(int32_t x=0; x<128; x++)
5069 {
5070 copy_mapscr(&screens[x], &copymapscr);
5071 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5072 //screens[x]=copymapscr;
5073 }
5074
5075 int32_t newcolor=getcolor();
5076 loadlvlpal(newcolor);
5077
5078 if(!(screens[cursor.screen].valid&mVALID))
5079 {
5080 newcolor=-1;
5081 }
5082
5083 if(newcolor!=oldcolor)
5084 {
5085 rebuild_trans_table();
5086 }
5087
5088 saved=false;
5089 }
5090 }
5091
5092 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5093 {
5094 if(can_paste)
5095 {
5096 for(int32_t i=0; i<10; i++)
5097 screens[screen].enemy[i]=copymapscr.enemy[i];
5098 }
5099 }
5100
5101 void zmap::setCopyFFC(int32_t n)
5102 {
5103 copyffc = n;
5104 }
5105
5106 void zmap::update_combo_cycling()
5107 {
5108 if(!prv_mode||!prv_cmbcycle)
5109 {
5110 return;
5111 }
5112
5113 int32_t x;
5114 int32_t newdata[176];
5115 int32_t newcset[176];
5116 bool restartanim[MAXCOMBOS] = {0};
5117
5118 for(int32_t i=0; i<176; i++)
5119 {
5120 newdata[i]=-1;
5121 newcset[i]=-1;
5122
5123 x=prvscr.data[i];
5124
5125 //time to restart
5126 if((combobuf[x].aclk>=combobuf[x].speed) &&
5127 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5128 combobuf[x].can_cycle())
5129 {
5130 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5131 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5132
5133 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5134 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5135 int32_t c = newdata[i];
5136
5137 if(combobuf[c].animflags & AF_CYCLE)
5138 {
5139 restartanim[c]=true;
5140 }
5141 }
5142 }
5143
5144 for(int32_t i=0; i<176; i++)
5145 {
5146 x=prvscr.data[i];
5147
5148 //time to restart
5149 if((combobuf[x].aclk>=combobuf[x].speed) &&
5150 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5151 combobuf[x].can_cycle())
5152 {
5153 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5154 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5155
5156 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5157 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5158 int32_t c = newdata[i];
5159
5160 if(combobuf[c].animflags & AF_CYCLE)
5161 {
5162 restartanim[c]=true;
5163 }
5164 }
5165 }
5166
5167 for(int32_t i=0; i<176; i++)
5168 {
5169 if(newdata[i]==-1)
5170 continue;
5171
5172 prvscr.data[i]=newdata[i];
5173 prvscr.cset[i]=newcset[i];
5174 }
5175
5176 word maxffc = prvscr.numFFC();
5177 for(word i=0; i<maxffc; i++)
5178 {
5179 ffcdata& ffc = prvscr.ffcs[i];
5180 newcombo const& cmb = combobuf[ffc.data];
5181
5182 //time to restart
5183 if((cmb.aclk>=cmb.speed) &&
5184 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5185 cmb.can_cycle())
5186 {
5187 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5188 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5189
5190 if(!(cmb.animflags & AF_CYCLENOCSET))
5191 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5192
5193 if(combobuf[ffc.data].animflags & AF_CYCLE)
5194 {
5195 restartanim[ffc.data]=true;
5196 }
5197 prvscr.ffcs[i].data = ffc.data;
5198 prvscr.ffcs[i].cset=ffc.cset;
5199 }
5200 }
5201
5202
5203 if(get_qr(qr_CMBCYCLELAYERS))
5204 {
5205 for(int32_t j=0; j<6; j++)
5206 {
5207 if(!prvlayers[j].valid)
5208 continue;
5209
5210 for(int32_t i=0; i<176; i++)
5211 {
5212 newdata[i]=-1;
5213 newcset[i]=-1;
5214
5215 x=(prvlayers[j]).data[i];
5216
5217 //time to restart
5218 if((combobuf[x].aclk>=combobuf[x].speed) &&
5219 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5220 combobuf[x].can_cycle())
5221 {
5222 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5223 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5224
5225 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5226 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5227 int32_t c = newdata[i];
5228
5229 if(combobuf[c].animflags & AF_CYCLE)
5230 {
5231 restartanim[c]=true;
5232 }
5233 }
5234 }
5235
5236 for(int32_t i=0; i<176; i++)
5237 {
5238 x=(prvlayers[j]).data[i];
5239
5240 //time to restart
5241 if((combobuf[x].aclk>=combobuf[x].speed) &&
5242 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5243 combobuf[x].can_cycle())
5244 {
5245 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5246 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5247
5248 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5249 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5250 int32_t c = newdata[i];
5251
5252 if(combobuf[c].animflags & AF_CYCLE)
5253 {
5254 restartanim[c]=true;
5255 }
5256 }
5257 }
5258
5259 for(int32_t i=0; i<176; i++)
5260 {
5261 if(newdata[i]==-1)
5262 continue;
5263
5264 prvlayers[j].data[i]=newdata[i];
5265 prvlayers[j].cset[i]=newcset[i];
5266 }
5267 }
5268 }
5269
5270 for(int32_t i=0; i<MAXCOMBOS; i++)
5271 {
5272 if(restartanim[i])
5273 {
5274 combobuf[i].tile = combobuf[i].o_tile;
5275 combobuf[i].cur_frame=0;
5276 combobuf[i].aclk = 0;
5277 }
5278 }
5279 }
5280
5281 void zmap::update_freeform_combos()
5282 {
5283 if(!prv_mode||!prv_cmbcycle)
5284 {
5285 return;
5286 }
5287
5288 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5289 word maxffc = prvscr.numFFC();
5290 for(int32_t i=0; i<maxffc; i++)
5291 {
5292 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5293 {
5294 for(int32_t j=0; j<maxffc; j++)
5295 {
5296 if(i!=j)
5297 {
5298 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5299 {
5300 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5301 {
5302 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5303 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5304 {
5305 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5306 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5307 if(prvscr.ffcs[j].flags&ffc_changethis)
5308 {
5309 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5310 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5311 }
5312
5313 if(prvscr.ffcs[j].flags&ffc_changenext)
5314 prvscr.ffcs[i].data += 1;
5315
5316 if(prvscr.ffcs[j].flags&ffc_changeprev)
5317 prvscr.ffcs[i].data -= 1;
5318
5319 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5320 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5321 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5322
5323 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5324 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5325 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5326 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5327
5328 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5329 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5330 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5331 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5332 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5333
5334 if(prvscr.ffcs[i].flags&ffc_carryover)
5335 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5336 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5337
5338 prvscr.ffcs[i].flags&=~ffc_changer;
5339 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5340 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5341
5342 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5343 {
5344 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5345 }
5346
5347 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5348 {
5349 int32_t k=0;
5350
5351 if(prvscr.ffcs[j].flags&ffc_swapnext)
5352 k=j<(MAXFFCS-1)?j+1:0;
5353
5354 if(prvscr.ffcs[j].flags&ffc_swapprev)
5355 k=j>0?j-1:(MAXFFCS-1);
5356
5357 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5358 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5359 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5360 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5361 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5362 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5363 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5364 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5365 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5366 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5367 }
5368 }
5369 }
5370 }
5371 }
5372 }
5373
5374 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5375 {
5376 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5377 {
5378 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5379 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5380 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5381 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5382 }
5383 else
5384 {
5385 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5386 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5387 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5388 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5389 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5390 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5391
5392 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5393 {
5394 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5395
5396 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5397
5398 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5399
5400 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5401 }
5402 }
5403 }
5404 else
5405 {
5406 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5407 prvscr.ffcs[i].delay--;
5408 }
5409
5410 if(prvscr.ffcs[i].x<-32)
5411 {
5412 if(prvscr.flags6&fWRAPAROUNDFF)
5413 {
5414 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5415 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5416 }
5417 else
5418 {
5419 prvscr.ffcs[i].data = 0;
5420 prvscr.ffcs[i].flags&=~ffc_carryover;
5421 }
5422 }
5423
5424 if(prvscr.ffcs[i].y<-32)
5425 {
5426 if(prvscr.flags6&fWRAPAROUNDFF)
5427 {
5428 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5429 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5430 }
5431 else
5432 {
5433 prvscr.ffcs[i].data = 0;
5434 prvscr.ffcs[i].flags&=~ffc_carryover;
5435 }
5436 }
5437
5438 if(prvscr.ffcs[i].x>=288)
5439 {
5440 if(prvscr.flags6&fWRAPAROUNDFF)
5441 {
5442 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5443 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5444 }
5445 else
5446 {
5447 prvscr.ffcs[i].data = 0;
5448 prvscr.ffcs[i].flags&=~ffc_carryover;
5449 }
5450 }
5451
5452 if(prvscr.ffcs[i].y>=208)
5453 {
5454 if(prvscr.flags6&fWRAPAROUNDFF)
5455 {
5456 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5457 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5458 }
5459 else
5460 {
5461 prvscr.ffcs[i].data = 0;
5462 prvscr.ffcs[i].flags&=~ffc_carryover;
5463 }
5464 }
5465
5466 }
5467 }
5468 }
5469
5470 void zmap::goto_dmapscr(int dmap, int scr)
5471 {
5472 setCurrMap(DMaps[dmap].map);
5473 setCurrScr(scr+DMaps[dmap].xoff);
5474 }
5475 void zmap::goto_mapscr(int map, int scr)
5476 {
5477 setCurrMap(map);
5478 setCurrScr(scr);
5479 }
5480
5481 void zmap::dowarp(int32_t type, int32_t index)
5482 {
5483 set_warpback();
5484 if(type==0)
5485 {
5486
5487 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5488 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5489
5490 switch(screens[cursor.screen].tilewarptype[index])
5491 {
5492 case wtCAVE:
5493 case wtNOWARP:
5494 break;
5495
5496 default:
5497 goto_dmapscr(dmap, scr);
5498 break;
5499 }
5500 }
5501 else if(type==1)
5502 {
5503 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5504 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5505
5506 switch(screens[cursor.screen].sidewarptype[index])
5507 {
5508 case wtCAVE:
5509 case wtNOWARP:
5510 break;
5511
5512 default:
5513 goto_dmapscr(dmap, scr);
5514 break;
5515 }
5516 }
5517 }
5518
5519 extern int32_t prv_twon;
5520
5521 void zmap::prv_dowarp(int32_t type, int32_t index)
5522 {
5523 if(type==0)
5524 {
5525
5526 int32_t dmap=prvscr.tilewarpdmap[index];
5527 int32_t scr=prvscr.tilewarpscr[index];
5528
5529 switch(prvscr.tilewarptype[index])
5530 {
5531 case wtCAVE:
5532 case wtNOWARP:
5533 break;
5534
5535 default:
5536 //setCurrMap(DMaps[dmap].map);
5537 //setCurrScr(scr+DMaps[dmap].xoff);
5538 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5539 loadlvlpal(getcolor());
5540 rebuild_trans_table();
5541 //prv_cmbcycle=0;
5542 break;
5543 }
5544 }
5545 else if(type==1)
5546 {
5547 int32_t dmap=prvscr.sidewarpdmap[index];
5548 int32_t scr=prvscr.sidewarpscr[index];
5549
5550 switch(prvscr.sidewarptype[index])
5551 {
5552 case wtCAVE:
5553 case wtNOWARP:
5554 break;
5555
5556 default:
5557 //setCurrMap(DMaps[dmap].map);
5558 //setCurrScr(scr+DMaps[dmap].xoff);
5559 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5560 loadlvlpal(getcolor());
5561 rebuild_trans_table();
5562 //prv_cmbcycle=0;
5563 break;
5564 }
5565 }
5566
5567 if(prv_twon)
5568 {
5569 prv_time=get_prvscr()->timedwarptics;
5570 }
5571
5572 //also reset FFC information (so that changers will work correctly) -DD
5573 memset(ffposx,0xFF,sizeof(int16_t)*32);
5574 memset(ffposy,0xFF,sizeof(int16_t)*32);
5575 memset(ffprvx,0xFF,sizeof(float)*32);
5576 memset(ffprvy,0xFF,sizeof(float)*32);
5577 }
5578
5579 void zmap::dowarp2(int32_t ring,int32_t index)
5580 {
5581 set_warpback();
5582 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5583 }
5584
5585 void zmap::set_warpback()
5586 {
5587 warpbackmap = cursor.map;
5588 warpbackscreen = cursor.screen;
5589 }
5590 bool zmap::has_warpback()
5591 {
5592 return warpbackmap && warpbackscreen
5593 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5594 }
5595 void zmap::warpback()
5596 {
5597 if(!has_warpback())
5598 return;
5599
5600 int m = cursor.map, s = cursor.screen;
5601 goto_mapscr(*warpbackmap, *warpbackscreen);
5602 warpbackmap = m;
5603 warpbackscreen = s;
5604 }
5605
5606 bool save_msgstrs(const char *path)
5607 {
5608 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5609
5610 if(!f)
5611 {
5612 return false;
5613 }
5614
5615 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5616 {
5617 pack_fclose(f);
5618 return true;
5619 }
5620
5621 pack_fclose(f);
5622 return false;
5623 }
5624
5625 1 bool save_strings_tsv(const char *path)
5626 {
5627 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5628
5629
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5630 {
5631 return false;
5632 }
5633
5634
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5635 {
5636 1 pack_fclose(f);
5637 1 return true;
5638 }
5639
5640 pack_fclose(f);
5641 return false;
5642 1 }
5643
5644 bool save_msgstrs_text(const char *path)
5645 {
5646 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5647
5648 if(!f)
5649 {
5650 return false;
5651 }
5652
5653 if(writestrings_text(f)==0)
5654 {
5655 pack_fclose(f);
5656 return true;
5657 }
5658
5659 pack_fclose(f);
5660 return false;
5661 }
5662
5663 bool load_msgstrs(const char *path, int32_t startstring)
5664 {
5665 //these are here to bypass compiler warnings about unused arguments
5666 startstring=startstring;
5667
5668 dword section_id;
5669 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5670
5671 if(!f)
5672 {
5673 return false;
5674 }
5675
5676 if(!p_mgetl(&section_id,f))
5677 {
5678 return false;
5679 }
5680
5681 if(section_id==ID_STRINGS)
5682 {
5683 if(readstrings(f, &header)==0)
5684 {
5685 pack_fclose(f);
5686 return true;
5687 }
5688 else
5689 {
5690 pack_fclose(f);
5691 return false;
5692 }
5693 }
5694
5695 pack_fclose(f);
5696 return false;
5697 }
5698
5699 bool load_strings_tsv(const char *path)
5700 {
5701 try
5702 {
5703 parse_strings_tsv(util::read_text_file(path));
5704 }
5705 catch (std::exception& ex)
5706 {
5707 InfoDialog("Import .tsv Error", ex.what()).show();
5708 return false;
5709 }
5710 return true;
5711 }
5712
5713 bool save_pals(const char *path)
5714 {
5715 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5716
5717 if(!f)
5718 {
5719 return false;
5720 }
5721
5722 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5723 {
5724 pack_fclose(f);
5725 return true;
5726 }
5727
5728 pack_fclose(f);
5729 return false;
5730 }
5731
5732 bool load_pals(const char *path, int32_t startcset)
5733 {
5734 dword section_id;
5735 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5736
5737 if(!f)
5738 {
5739 return false;
5740 }
5741
5742 if(!p_mgetl(&section_id,f))
5743 {
5744 return false;
5745 }
5746
5747 if(section_id==ID_CSETS)
5748 {
5749 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5750 {
5751 pack_fclose(f);
5752 loadlvlpal(Color);
5753 return true;
5754 }
5755 else
5756 {
5757 pack_fclose(f);
5758 return false;
5759 }
5760 }
5761
5762 return false;
5763 }
5764
5765 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5766 bool save_guys(const char *path)
5767 {
5768 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5769
5770 if(!f)
5771 {
5772 return false;
5773 }
5774
5775 /*
5776 int32_t id = ID_GUYS;
5777 if(!p_mputl(id,f))
5778 {
5779 return false;
5780 }
5781 */
5782
5783 zquestheader h;
5784 h.zelda_version = 0x250;
5785 h.build = 21;
5786
5787 if(writeguys(f, &h)==0)
5788 {
5789 pack_fclose(f);
5790 return true;
5791 }
5792
5793 pack_fclose(f);
5794 return false;
5795 }
5796
5797 bool load_guys(const char *path)
5798 {
5799 dword section_id;
5800 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5801
5802 if(!f)
5803 {
5804 return false;
5805 }
5806
5807 if(!p_mgetl(&section_id,f))
5808 {
5809 pack_fclose(f);
5810 return false;
5811 }
5812
5813 zquestheader h;
5814 h.zelda_version = 0x250;
5815 h.build = 21;
5816
5817 if(section_id==ID_GUYS)
5818 {
5819 if(readguys(f, &h)==0)
5820 {
5821 pack_fclose(f);
5822 return true;
5823 }
5824 }
5825
5826 pack_fclose(f);
5827 return false;
5828 }
5829
5830
5831 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5832 bool save_combo_alias(const char *path)
5833 {
5834 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5835
5836 if(!f)
5837 {
5838 return false;
5839 }
5840
5841 zquestheader h;
5842 h.zelda_version = 0x250;
5843 h.build = 21;
5844
5845 if(writecomboaliases(f, 0, 0)==0)
5846 {
5847 pack_fclose(f);
5848 return true;
5849 }
5850
5851 pack_fclose(f);
5852 return false;
5853 }
5854
5855 bool load_combo_alias(const char *path)
5856 {
5857 dword section_id;
5858 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5859
5860 if(!f)
5861 {
5862 return false;
5863 }
5864
5865 if(!p_mgetl(&section_id,f))
5866 {
5867 pack_fclose(f);
5868 return false;
5869 }
5870
5871 zquestheader h;
5872 h.zelda_version = 0x250;
5873 h.build = 21;
5874
5875 if(section_id==ID_COMBOALIASES)
5876 {
5877 if(readcomboaliases(f, &h, 0, 0)==0)
5878 {
5879 pack_fclose(f);
5880 return true;
5881 }
5882 }
5883
5884 pack_fclose(f);
5885 return false;
5886 }
5887
5888 bool load_zgp(const char *path)
5889 {
5890 dword section_id;
5891 dword section_version;
5892 dword section_cversion;
5893 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5894
5895 if(!f)
5896 return false;
5897
5898 if(!p_mgetl(&section_id,f))
5899 {
5900 pack_fclose(f);
5901 return false;
5902 }
5903
5904 if(section_id!=ID_GRAPHICSPACK)
5905 {
5906 pack_fclose(f);
5907 return false;
5908 }
5909
5910 //section version info
5911 if(!p_igetw(&section_version,f))
5912 {
5913 return 2;
5914 }
5915
5916 if(!p_igetw(&section_cversion,f))
5917 {
5918 return 3;
5919 }
5920
5921 //tiles
5922 if(!p_mgetl(&section_id,f))
5923 {
5924 pack_fclose(f);
5925 return false;
5926 }
5927
5928 if(section_id==ID_TILES)
5929 {
5930 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5931 {
5932 pack_fclose(f);
5933 init_tiles(true, &header);
5934 return false;
5935 }
5936 }
5937 else
5938 {
5939 pack_fclose(f);
5940 return false;
5941 }
5942
5943 //combos
5944 if(!p_mgetl(&section_id,f))
5945 {
5946 pack_fclose(f);
5947 return false;
5948 }
5949
5950 if(section_id==ID_COMBOS)
5951 {
5952 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5953 {
5954 pack_fclose(f);
5955 return false;
5956 }
5957 }
5958 else
5959 {
5960 pack_fclose(f);
5961 return false;
5962 }
5963
5964 //palettes
5965 if(!p_mgetl(&section_id,f))
5966 {
5967 pack_fclose(f);
5968 return false;
5969 }
5970
5971 if(section_id==ID_CSETS)
5972 {
5973 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5974 {
5975 pack_fclose(f);
5976 return false;
5977 }
5978 }
5979 else
5980 {
5981 pack_fclose(f);
5982 return false;
5983 }
5984
5985 //items
5986 if(!p_mgetl(&section_id,f))
5987 {
5988 pack_fclose(f);
5989 return false;
5990 }
5991
5992 if(section_id==ID_ITEMS)
5993 {
5994 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5995 {
5996 pack_fclose(f);
5997 return false;
5998 }
5999 }
6000 else
6001 {
6002 pack_fclose(f);
6003 return false;
6004 }
6005
6006 //weapons
6007 if(!p_mgetl(&section_id,f))
6008 {
6009 pack_fclose(f);
6010 return false;
6011 }
6012
6013 if(section_id==ID_WEAPONS)
6014 {
6015 if(readweapons(f, &header)!=0)
6016 {
6017 pack_fclose(f);
6018 return false;
6019 }
6020 }
6021 else
6022 {
6023 pack_fclose(f);
6024 return false;
6025 }
6026
6027 //read the triforce pieces info and make sure it worked
6028 //really do this?
6029
6030 //read the game icons info and make sure it worked
6031 if(!p_mgetl(&section_id,f))
6032 {
6033 pack_fclose(f);
6034 return false;
6035 }
6036
6037 if(section_id==ID_ICONS)
6038 {
6039 if(readgameicons(f, &header, &QMisc)!=0)
6040 {
6041 pack_fclose(f);
6042 return false;
6043 }
6044 }
6045 else
6046 {
6047 pack_fclose(f);
6048 return false;
6049 }
6050
6051 //read the misc colors info and map styles info and make sure it worked
6052 if(!p_mgetl(&section_id,f))
6053 {
6054 pack_fclose(f);
6055 return false;
6056 }
6057
6058 if(section_id==ID_COLORS)
6059 {
6060 if(readmisccolors(f, &header, &QMisc)!=0)
6061 {
6062 pack_fclose(f);
6063 return false;
6064 }
6065 }
6066 else
6067 {
6068 pack_fclose(f);
6069 return false;
6070 }
6071
6072 //read the door combo sets and make sure it worked
6073 if(!p_mgetl(&section_id,f))
6074 {
6075 pack_fclose(f);
6076 return false;
6077 }
6078
6079 if(section_id==ID_DOORS)
6080 {
6081 if(readdoorcombosets(f, &header)!=0)
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086 }
6087 else
6088 {
6089 pack_fclose(f);
6090 return false;
6091 }
6092
6093 //read the template screens and make sure it worked
6094 //really do this?
6095
6096 //yay! it worked! close the file and say everything was ok.
6097 loadlvlpal(Color);
6098 setup_combo_animations();
6099 setup_combo_animations2();
6100 pack_fclose(f);
6101 return true;
6102 }
6103
6104 bool save_zgp(const char *path)
6105 {
6106 reset_combo_animations();
6107 reset_combo_animations2();
6108
6109 //open the file
6110 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6111
6112 if(!f)
6113 return false;
6114
6115 dword section_id=ID_GRAPHICSPACK;
6116 dword section_version=V_GRAPHICSPACK;
6117 dword section_cversion=CV_GRAPHICSPACK;
6118
6119 //section id
6120 if(!p_mputl(section_id,f))
6121 {
6122 return 1;
6123 }
6124
6125 //section version info
6126 if(!p_iputw(section_version,f))
6127 {
6128 return 2;
6129 }
6130
6131 if(!p_iputw(section_cversion,f))
6132 {
6133 return 3;
6134 }
6135
6136 //tiles
6137 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6138 {
6139 pack_fclose(f);
6140 return false;
6141 }
6142
6143 //combos
6144 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6145 {
6146 pack_fclose(f);
6147 return false;
6148 }
6149
6150 //palettes
6151 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6152 {
6153 pack_fclose(f);
6154 return false;
6155 }
6156
6157 //items
6158 if(writeitems(f, &header)!=0)
6159 {
6160 pack_fclose(f);
6161 return false;
6162 }
6163
6164 //weapons
6165 if(writeweapons(f, &header)!=0)
6166 {
6167 pack_fclose(f);
6168 return false;
6169 }
6170
6171 //write the triforce pieces info and make sure it worked
6172 //really do this?
6173
6174 //write the game icons info and make sure it worked
6175 if(writegameicons(f, &header)!=0)
6176 {
6177 pack_fclose(f);
6178 return false;
6179 }
6180
6181 //write the misc colors info and map styles info and make sure it worked
6182 if(writemisccolors(f, &header)!=0)
6183 {
6184 pack_fclose(f);
6185 return false;
6186 }
6187
6188 //write the door combo sets and make sure it worked
6189 if(writedoorcombosets(f, &header)!=0)
6190 {
6191 pack_fclose(f);
6192 return false;
6193 }
6194
6195 //write the template screens and make sure it worked
6196 //really do this?
6197
6198 pack_fclose(f);
6199 return true;
6200 }
6201
6202 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6203 {
6204 //open the file
6205 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6206
6207 if(!f)
6208 return false;
6209
6210 dword section_id=ID_SUBSCREEN;
6211 dword s_version=V_SUBSCREEN;
6212 dword s_cversion=CV_SUBSCREEN;
6213
6214 if(!p_mputl(section_id,f))
6215 {
6216 pack_fclose(f);
6217 return false;
6218 }
6219
6220 if(!p_iputw(s_version,f))
6221 {
6222 pack_fclose(f);
6223 return false;
6224 }
6225
6226 if(!p_iputw(s_cversion,f))
6227 {
6228 pack_fclose(f);
6229 return false;
6230 }
6231
6232 if(savefrom.write(f))
6233 {
6234 pack_fclose(f);
6235 return false;
6236 }
6237
6238 pack_fclose(f);
6239 return true;
6240 }
6241
6242 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6243 {
6244 //open the file
6245 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6246
6247 if(!f)
6248 return false;
6249
6250 dword section_id;
6251 dword s_version;
6252 dword s_cversion;
6253
6254 if(!p_mgetl(&section_id,f))
6255 {
6256 pack_fclose(f);
6257 return false;
6258 }
6259
6260 if(section_id!=ID_SUBSCREEN)
6261 {
6262 pack_fclose(f);
6263 return false;
6264 }
6265
6266 if(!p_igetw(&s_version,f))
6267 {
6268 pack_fclose(f);
6269 return false;
6270 }
6271
6272 if(!p_igetw(&s_cversion,f))
6273 {
6274 pack_fclose(f);
6275 return false;
6276 }
6277
6278 if(s_version < 8)
6279 {
6280 subscreen_group g;
6281 memset(&g,0,sizeof(subscreen_group));
6282 if(read_one_old_subscreen(f,&g,s_version)!=0)
6283 {
6284 pack_fclose(f);
6285 return false;
6286 }
6287 if(g.ss_type != loadto.sub_type)
6288 {
6289 pack_fclose(f);
6290 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6291 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6292 return false;
6293 }
6294 loadto.clear();
6295 if(g.objects[0].type != ssoNULL)
6296 loadto.load_old(g);
6297 }
6298 else
6299 {
6300 ZCSubscreen tmp = ZCSubscreen();
6301 if (tmp.read(f, s_version))
6302 {
6303 pack_fclose(f);
6304 return false;
6305 }
6306 if(tmp.sub_type != loadto.sub_type)
6307 {
6308 pack_fclose(f);
6309 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6310 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6311 return false;
6312 }
6313 loadto.clear();
6314 loadto = tmp;
6315 }
6316
6317 pack_fclose(f);
6318 return true;
6319 }
6320
6321 bool setMapCount2(int32_t c)
6322 {
6323 int32_t oldmapcount=map_count;
6324 int32_t currmap=Map.getCurrMap();
6325
6326 bound(c,1,MAXMAPS);
6327 map_count=c;
6328
6329 try
6330 {
6331 TheMaps.resize(c*MAPSCRS);
6332 Map.force_refr_pointer();
6333 map_autolayers.resize(c*6);
6334 }
6335 catch(...)
6336 {
6337 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6338 return false;
6339 }
6340
6341 bound(currmap,0,c-1);
6342 if(map_count>oldmapcount)
6343 {
6344 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6345 {
6346 Map.setCurrMap(mc);
6347
6348 for(int32_t ms=0; ms<MAPSCRS; ms++)
6349 {
6350 Map.clearscr(ms);
6351 }
6352 }
6353 Map.setCurrMap(currmap);
6354 }
6355 else
6356 {
6357 Map.setCurrMap(currmap);
6358 if(!layers_valid(Map.CurrScr()))
6359 fix_layers(Map.CurrScr(), false);
6360
6361 for(int32_t i=0; i<MAXDMAPS; i++)
6362 {
6363 if(DMaps[i].map>=map_count)
6364 {
6365 DMaps[i].map=map_count-1;
6366 }
6367 }
6368 }
6369
6370 return true;
6371 }
6372
6373 extern BITMAP *bmap;
6374
6375 static bool loading_file_new = false;
6376 1 int32_t init_quest(std::string tileset_path)
6377 {
6378
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (tileset_path.empty())
6379 tileset_path = DEFAULT_TILESET;
6380
6381 1 loading_file_new = true;
6382 1 load_quest(tileset_path.c_str());
6383 1 loading_file_new = false;
6384
6385 1 set_window_title("ZC Editor - Untitled Quest");
6386 1 zinit.last_map = 0;
6387 1 zinit.last_screen = 0;
6388
6389
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(bmap != NULL)
6390 {
6391 destroy_bitmap(bmap);
6392 bmap=NULL;
6393 }
6394
6395 1 return 0;
6396 }
6397
6398 void set_questpwd(std::string_view pwd, bool use_keyfile)
6399 {
6400 header.use_keyfile=use_keyfile;
6401
6402 // string_view actually has some quirks that make it less than ideal here.
6403 // It'd probably be best to replace it, but this works for now.
6404 memset(header.password, 0, 256);
6405 strcpy(header.password, pwd.data());
6406 header.dirty_password=true;
6407
6408 cvs_MD5Context ctx;
6409 cvs_MD5Init(&ctx);
6410 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6411 cvs_MD5Final(header.pwd_hash, &ctx);
6412 }
6413
6414
6415 bool is_null_pwd_hash(uint8_t *pwd_hash)
6416 {
6417 cvs_MD5Context ctx;
6418 uint8_t md5sum[16];
6419 char pwd[2]="";
6420
6421 cvs_MD5Init(&ctx);
6422 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6423 cvs_MD5Final(md5sum, &ctx);
6424
6425 return (memcmp(md5sum,pwd_hash,16)==0);
6426 }
6427
6428 static DIALOG pwd_dlg[] =
6429 {
6430 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6431 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6432 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6433 // 2 (filename)
6434 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6435 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6436 // 4 (challenge hash)
6437 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6438 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6439 // 6 (password)
6440 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6441 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6442 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6443 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6444 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6445 };
6446
6447 int32_t reverse_string(char* str)
6448 {
6449
6450 if(NULL==str)
6451 {
6452 return -1; //no string
6453 }
6454
6455 int32_t l=(int32_t)strlen(str)-1; //get the string length
6456
6457 if(1==l)
6458 {
6459 return 1;
6460 }
6461
6462 char c;
6463
6464 for(int32_t x=0; x < l; x++,l--)
6465 {
6466 c = str[x];
6467 str[x] = str[l];
6468 str[l] = c;
6469 }
6470
6471 return 0;
6472 }
6473
6474 #ifdef __GNUC__
6475 #pragma GCC diagnostic push
6476 #pragma GCC diagnostic ignored "-Wunreachable-code"
6477 #endif
6478
6479 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6480 {
6481
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (is_headless())
6482 9 return 1;
6483
6484 #ifdef __EMSCRIPTEN__
6485 return 1;
6486 #endif
6487
6488 //Protection against compiling a release version with password protection off.
6489 static bool passguard = false;
6490
6491 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6492 #define MUST_HAVE_PASSWORD
6493 passguard = true;
6494 #endif
6495
6496 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6497 #if (defined _MSC_VER || defined _NPASS)
6498 return 1;
6499 #endif
6500 #endif
6501 if(devpwd()) return 1;
6502
6503 char hash_string[33];
6504
6505 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6506 {
6507 return 1;
6508 }
6509
6510 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6511 return true;
6512
6513 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6514 pwd_dlg[2].dp=get_filename(filename);
6515 cvs_MD5Context ctx;
6516 uint8_t md5sum[16]={0};
6517 char response[33]="";
6518 char prompt[256]="";
6519
6520 memcpy(md5sum, hdr->pwd_hash, 16);
6521
6522 for(int32_t i=0; i<300; ++i)
6523 {
6524 for(int32_t j=0; j<16; ++j)
6525 {
6526 sprintf(response+j*2, "%02x", md5sum[j]);
6527 }
6528
6529 if(i&1)
6530 {
6531 reverse_string(response);
6532 }
6533
6534 if(i==149)
6535 {
6536 strcpy(hash_string, response);
6537 }
6538
6539 cvs_MD5Init(&ctx);
6540 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6541 cvs_MD5Final(md5sum, &ctx);
6542 }
6543
6544 pwd_dlg[4].dp=hash_string;
6545
6546 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6547 {
6548 sprintf(prompt,"%s",response);
6549 }
6550
6551 pwd_dlg[6].dp=prompt;
6552
6553 large_dialog(pwd_dlg);
6554
6555 int32_t cancel = do_zqdialog(pwd_dlg,6);
6556
6557 if(cancel == 8)
6558 return 2;
6559
6560 bool ret=check_questpwd(hdr, prompt);
6561
6562 if(!ret)
6563 {
6564 ret=(strcmp(response,prompt)==0);
6565 }
6566 return ret ? 1 : 0;
6567 9 }
6568
6569 void set_rules(byte* newrules);
6570 8 void popup_bugfix_dlg(const char* cfg)
6571 {
6572 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6573
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6574 {
6575
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6576
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6577 "\nWould you like to apply them?"
6578 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6579 8 [&](bool ret,bool dsa)
6580 {
6581 if(ret)
6582 {
6583 applyRuleTemplate(ruletemplateFixCompat);
6584 }
6585 if(dsa)
6586 {
6587 zc_set_config("zquest",cfg,1);
6588 }
6589 },
6590
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6591 0,false, //timeout - none
6592 true //"Don't show this again"
6593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6594 8 }
6595 8 }
6596
6597 #ifdef __GNUC__
6598 #pragma GCC diagnostic pop
6599 #endif
6600
6601 9 int32_t load_quest(const char *filename, bool show_progress)
6602 {
6603 char buf[2048];
6604 byte skip_flags[4];
6605
6606 // For File>New, don't clear the maps because tilesets (like Cambria) have a more friendly
6607 // starter experience that way.
6608 9 dword tileset_flags = 0;
6609
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (loading_file_new)
6610 1 tileset_flags = TILESET_CLEARSCRIPTS | TILESET_CLEARHEADER;
6611
6612
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6613 {
6614 36 skip_flags[i]=0;
6615 36 }
6616
2/2
✓ Branch 0 taken 6237 times.
✓ Branch 1 taken 9 times.
6246 for(int32_t i=0; i<qr_MAX; i++)
6617 6237 set_qr(i,0);
6618 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6619
6620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6621 {
6622 init_quest(DEFAULT_TILESET);
6623 }
6624 else
6625 {
6626 9 int32_t accessret = quest_access(filename, &header);
6627
6628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6629 {
6630 init_quest(DEFAULT_TILESET);
6631
6632 if(accessret == 0)
6633 ret=qe_pwd;
6634 else
6635 ret=qe_cancel;
6636 }
6637 else
6638 {
6639 9 Map.clear();
6640 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6641 9 Map.setCurrScr(zinit.last_screen);
6642
6643
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
6644
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6645
6646 extern int32_t current_mappage;
6647 9 current_mappage = 0;
6648 9 bool found_default = false;
6649
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6650 {
6651 65 auto &pg = map_page[q];
6652
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6653 {
6654 2 current_mappage = q;
6655 2 break;
6656 }
6657
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6658 56 continue;
6659 else
6660 {
6661 7 current_mappage = q;
6662 7 found_default = true;
6663 }
6664 7 }
6665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 refresh(rALL);
6666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 refresh_pal();
6667
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 set_rules(quest_rules);
6668 9 saved = true;
6669
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6670
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 popup_bugfix_dlg("dsa_compatrule");
6671
6672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(bmap != NULL)
6673 {
6674 destroy_bitmap(bmap);
6675 bmap=NULL;
6676 }
6677
6678
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (show_progress)
6679 {
6680
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6681
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_window_title(buf);
6682 1 }
6683 9 }
6684 }
6685
6686 9 Map.ClearCommandHistory();
6687
6688
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (!is_headless())
6689 {
6690 void load_size_poses();
6691 load_size_poses();
6692 }
6693
6694 9 return ret;
6695 }
6696
6697 int32_t load_tileset(const char *filename, dword tsetflags)
6698 {
6699 char buf[2048];
6700 byte skip_flags[4];
6701
6702 for(int32_t i=0; i<4; ++i)
6703 skip_flags[i]=0;
6704 for(int32_t i=0; i<qr_MAX; i++)
6705 set_qr(i,0);
6706 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6707
6708 if(ret!=qe_OK)
6709 init_quest(DEFAULT_TILESET);
6710 else
6711 {
6712 int32_t accessret = quest_access(filename, &header);
6713
6714 if(accessret != 1)
6715 {
6716 init_quest(DEFAULT_TILESET);
6717
6718 if(accessret == 0)
6719 ret=qe_pwd;
6720 else
6721 ret=qe_cancel;
6722 }
6723 else
6724 {
6725 Map.clear();
6726 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6727 Map.setCurrScr(zinit.last_screen);
6728 extern int32_t current_mappage;
6729 current_mappage = 0;
6730 bool found_default = false;
6731 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6732 {
6733 auto &pg = map_page[q];
6734 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6735 {
6736 current_mappage = q;
6737 break;
6738 }
6739 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6740 continue;
6741 else
6742 {
6743 current_mappage = q;
6744 found_default = true;
6745 }
6746 }
6747 refresh(rALL);
6748 refresh_pal();
6749 set_rules(quest_rules);
6750 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6751 popup_bugfix_dlg("dsa_compatrule");
6752
6753 if(bmap != NULL)
6754 {
6755 destroy_bitmap(bmap);
6756 bmap=NULL;
6757 }
6758
6759 set_window_title("ZC Editor - Untitled Quest");
6760 first_save = saved = false;
6761 memset(filepath,0,255);
6762 memset(temppath,0,255);
6763 }
6764 }
6765
6766 Map.ClearCommandHistory();
6767
6768 return ret;
6769 }
6770
6771 60 bool write_midi(MIDI *m,PACKFILE *f)
6772 {
6773 int32_t c;
6774
6775
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6776
6777
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6778 {
6779
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6780
6781
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6782 {
6783
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6784 return false;
6785 492 }
6786 1920 }
6787
6788 60 return true;
6789 60 }
6790
6791 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6792 {
6793 6 dword section_id=ID_HEADER;
6794 6 dword section_version=V_HEADER;
6795 6 dword section_cversion=CV_HEADER;
6796 6 dword section_size=0;
6797
6798 //file header string
6799
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6800 {
6801 new_return(1);
6802 }
6803
6804 //section id
6805
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6806 {
6807 new_return(2);
6808 }
6809
6810 //section version info
6811
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6812 {
6813 new_return(3);
6814 }
6815
6816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6817 {
6818 new_return(4);
6819 }
6820
6821
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6822 {
6823 12 fake_pack_writing=(writecycle==0);
6824
6825 //section size
6826
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6827 {
6828 new_return(5);
6829 }
6830
6831 12 writesize=0;
6832
6833 //finally... section data
6834
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6835 {
6836 new_return(6);
6837 }
6838
6839
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6840 {
6841 new_return(7);
6842 }
6843
6844
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6845 {
6846 new_return(8);
6847 }
6848
6849
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6850 {
6851 new_return(10);
6852 }
6853
6854
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6855 {
6856 new_return(11);
6857 }
6858
6859
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6860 {
6861 new_return(12);
6862 }
6863
6864
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
6865 {
6866 new_return(13);
6867 }
6868
6869
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
6870 {
6871 new_return(14);
6872 }
6873
6874
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
6875 {
6876 new_return(15);
6877 }
6878
6879
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
6880 {
6881 new_return(16);
6882 }
6883
6884
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6885 {
6886 new_return(17);
6887 }
6888
6889
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6890 {
6891 new_return(19);
6892 }
6893
6894
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
6895 //this is for map count, it seems. -Z
6896 {
6897 new_return(20);
6898 }
6899
6900 12 auto version = getVersion();
6901
6902
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
6903 {
6904 new_return(21);
6905 }
6906
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
6907 {
6908 new_return(22);
6909 }
6910
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
6911 {
6912 new_return(23);
6913 }
6914 // Fourth component is deprecated.
6915
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6916 {
6917 new_return(24);
6918 }
6919
6920 // Numerous prerelease stages is deprecated.
6921
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6922 {
6923 new_return(25);
6924 }
6925
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6926 {
6927 new_return(26);
6928 }
6929
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6930 {
6931 new_return(27);
6932 }
6933
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6934 {
6935 new_return(28);
6936 }
6937
6938
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
6939 {
6940 new_return(29);
6941 }
6942
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
6943 {
6944 new_return(30);
6945 }
6946
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
6947 {
6948 new_return(31);
6949 }
6950
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
6951 {
6952 new_return(32);
6953 }
6954
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
6955 {
6956 new_return(33);
6957 }
6958
6959
6960
6961 char tempsig[256];
6962 12 memset(tempsig, 0, 256);
6963 12 strcpy(tempsig, DEV_SIGNOFF);
6964
6965
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
6966 {
6967 new_return(34);
6968 }
6969
6970 char tempcompilersig[256];
6971 12 memset(tempcompilersig, 0, 256);
6972 12 strcpy(tempcompilersig, COMPILER_NAME);
6973
6974
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
6975 {
6976 new_return(35);
6977 }
6978
6979 char tempcompilerversion[256];
6980 12 memset(tempcompilerversion, 0, 256);
6981 #ifdef _MSC_VER
6982 zc_itoa(_MSC_VER,tempcompilerversion,10);
6983 #else
6984 12 strcpy(tempcompilerversion, COMPILER_VERSION);
6985 #endif
6986
6987
6988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
6989 {
6990 new_return(36);
6991 }
6992
6993
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
6994 {
6995 new_return(37);
6996 }
6997
6998
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
6999 {
7000 new_return(38);
7001 }
7002 #ifdef _MSC_VER
7003 if(!p_iputl((_MSC_VER / 100),f))
7004 {
7005 new_return(39);
7006 }
7007 #else
7008
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7009 {
7010 new_return(39);
7011 }
7012 #endif
7013
7014
7015
7016 #ifdef _MSC_VER
7017 if(!p_iputl((_MSC_VER % 100),f))
7018 {
7019 new_return(41);
7020 }
7021 #else
7022
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7023 {
7024 new_return(41);
7025 }
7026 #endif
7027
7028 #ifdef _MSC_VER
7029 # if _MSC_VER >= 1400
7030 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7031 {
7032 new_return(40);
7033 }
7034 # else
7035 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7036 {
7037 new_return(40);
7038 }
7039 #endif
7040 #else
7041
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7042 {
7043 new_return(40);
7044 }
7045 #endif
7046
7047 #ifdef _MSC_VER
7048 if(!p_iputl((_MSC_BUILD),f))
7049 {
7050 new_return(42);
7051 }
7052 #else
7053
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7054 {
7055 new_return(42);
7056 }
7057 #endif
7058
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7059 {
7060 new_return(43);
7061 }
7062
7063 char tempmodulename[1024];
7064 12 memset(tempmodulename, 0, 1024);
7065 12 strcpy(tempmodulename, moduledata.module_name);
7066
7067
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7068 {
7069 new_return(44);
7070 }
7071
7072 char tempdate[256];
7073 12 memset(tempdate, 0, 256);
7074 12 strcpy(tempdate, __DATE__);
7075
7076
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7077 {
7078 new_return(45);
7079 }
7080 char temptime[256];
7081 12 memset(temptime, 0, 256);
7082 12 strcpy(temptime, __TIME__);
7083
7084
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7085 {
7086 new_return(46);
7087 }
7088
7089
7090 char temptimezone[6];
7091 12 memset(temptimezone, 0, 6);
7092 12 strcpy(temptimezone, __TIMEZONE__);
7093
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7094 {
7095 new_return(47);
7096 }
7097
7098
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7099 {
7100 new_return(48);
7101 }
7102
7103
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7104 {
7105 new_return(49);
7106 }
7107
7108
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7109 {
7110 new_return(50);
7111 }
7112
7113
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7114 {
7115 6 section_size=writesize;
7116 6 }
7117 12 }
7118
7119
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7120 {
7121 char ebuf[80];
7122 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7123 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7124 }
7125
7126 6 new_return(0);
7127 }
7128
7129 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7130 {
7131 //these are here to bypass compiler warnings about unused arguments
7132 6 Header=Header;
7133
7134 6 dword section_id=ID_RULES;
7135 6 dword section_version=V_RULES;
7136 6 dword section_cversion=CV_RULES;
7137 6 dword section_size=0;
7138
7139 //section id
7140
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7141 {
7142 new_return(1);
7143 }
7144
7145 //section version info
7146
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7147 {
7148 new_return(2);
7149 }
7150
7151
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7152 {
7153 new_return(3);
7154 }
7155
7156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7157 {
7158 new_return(6);
7159 }
7160
7161
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7162 {
7163 12 fake_pack_writing=(writecycle==0);
7164
7165 //section size
7166
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7167 {
7168 new_return(4);
7169 }
7170
7171 12 writesize=0;
7172
7173 //finally... section data
7174
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7175 {
7176 new_return(5);
7177 }
7178
7179
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7180 {
7181 6 section_size=writesize;
7182 6 }
7183 12 }
7184
7185
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7186 {
7187 char ebuf[80];
7188 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7189 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7190 }
7191
7192 6 new_return(0);
7193 }
7194
7195
7196 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7197 {
7198 //these are here to bypass compiler warnings about unused arguments
7199 6 Header=Header;
7200
7201 6 dword section_id=ID_DOORS;
7202 6 dword section_version=V_DOORS;
7203 6 dword section_cversion=CV_DOORS;
7204 6 dword section_size=0;
7205
7206 //section id
7207
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7208 {
7209 new_return(1);
7210 }
7211
7212 //section version info
7213
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7214 {
7215 new_return(2);
7216 }
7217
7218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7219 {
7220 new_return(3);
7221 }
7222
7223
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7224 {
7225 12 fake_pack_writing=(writecycle==0);
7226
7227 //section size
7228
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7229 {
7230 new_return(4);
7231 }
7232
7233 12 writesize=0;
7234
7235 //finally... section data
7236
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7237 {
7238 new_return(5);
7239 }
7240
7241
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7242 {
7243 //name
7244 char name[21];
7245 164 memset(name, 21, (char)0);
7246 164 strcpy(name, DoorComboSetNames[i].c_str());
7247
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(name,sizeof(name),f))
7248 {
7249 new_return(6);
7250 }
7251
7252 //up door
7253
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7254 {
7255
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7256 {
7257
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7258 {
7259 new_return(7);
7260 }
7261 5904 }
7262 1476 }
7263
7264
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7265 {
7266
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7267 {
7268
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7269 {
7270 new_return(8);
7271 }
7272 5904 }
7273 1476 }
7274
7275 //down door
7276
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7277 {
7278
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7279 {
7280
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7281 {
7282 new_return(9);
7283 }
7284 5904 }
7285 1476 }
7286
7287
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7288 {
7289
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7290 {
7291
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7292 {
7293 new_return(10);
7294 }
7295 5904 }
7296 1476 }
7297
7298
7299 //left door
7300
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7301 {
7302
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7303 {
7304
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7305
7306 {
7307 new_return(11);
7308 }
7309 8856 }
7310 1476 }
7311
7312
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7313 {
7314
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7315 {
7316
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7317 {
7318 new_return(12);
7319 }
7320 8856 }
7321 1476 }
7322
7323 //right door
7324
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7325 {
7326
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7327 {
7328
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7329 {
7330 new_return(13);
7331 }
7332 8856 }
7333 1476 }
7334
7335
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7336 {
7337
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7338 {
7339
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7340 {
7341 new_return(14);
7342 }
7343 8856 }
7344 1476 }
7345
7346
7347 //up bomb rubble
7348
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7349 {
7350
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7351 {
7352 new_return(15);
7353 }
7354 328 }
7355
7356
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7357 {
7358
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7359 {
7360 new_return(16);
7361 }
7362 328 }
7363
7364 //down bomb rubble
7365
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7366 {
7367
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7368 {
7369 new_return(17);
7370 }
7371 328 }
7372
7373
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7374 {
7375
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7376 {
7377 new_return(18);
7378 }
7379 328 }
7380
7381 //left bomb rubble
7382
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7383 {
7384
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7385 {
7386 new_return(19);
7387 }
7388 492 }
7389
7390
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7391 {
7392
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7393 {
7394 new_return(20);
7395 }
7396 492 }
7397
7398 //right bomb rubble
7399
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7400 {
7401
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7402 {
7403 new_return(21);
7404 }
7405 492 }
7406
7407
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7408 {
7409
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7410 {
7411 new_return(22);
7412 }
7413 492 }
7414
7415 //walkthrough stuff
7416
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7417 {
7418
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7419 {
7420 new_return(23);
7421 }
7422 656 }
7423
7424
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7425 {
7426
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7427 {
7428 new_return(24);
7429 }
7430 656 }
7431
7432 //flags
7433
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7434 {
7435
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7436 {
7437 new_return(25);
7438 }
7439 328 }
7440 164 }
7441
7442
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7443 {
7444 6 section_size=writesize;
7445 6 }
7446 12 }
7447
7448
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7449 {
7450 char ebuf[80];
7451 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7452 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7453 }
7454
7455 6 new_return(0);
7456 }
7457
7458 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7459 {
7460 //these are here to bypass compiler warnings about unused arguments
7461 6 version=version;
7462 6 build=build;
7463
7464 6 word dmap_count=count_dmaps();
7465 6 dword section_id=ID_DMAPS;
7466 6 dword section_version=V_DMAPS;
7467 6 dword section_cversion=CV_DMAPS;
7468 6 dword section_size=0;
7469
7470 //section id
7471
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7472 {
7473 new_return(1);
7474 }
7475
7476 //section version info
7477
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7478 {
7479 new_return(2);
7480 }
7481
7482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7483 {
7484 new_return(3);
7485 }
7486
7487
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7488 {
7489 12 fake_pack_writing=(writecycle==0);
7490
7491 //section size
7492
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7493 {
7494 new_return(4);
7495 }
7496
7497 12 writesize=0;
7498
7499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7501
7502 //finally... section data
7503
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7504 {
7505 new_return(5);
7506 }
7507
7508
7509
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7510 {
7511 6144 DMaps[i].validate_subscreens();
7512
7513
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7514 {
7515 new_return(6);
7516 }
7517
7518
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7519 {
7520 new_return(7);
7521 }
7522
7523
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7524 {
7525 new_return(8);
7526 }
7527
7528
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7529 {
7530 new_return(9);
7531 }
7532
7533
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7534 {
7535 new_return(10);
7536 }
7537
7538
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7539 {
7540 new_return(11);
7541 }
7542
7543
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7544 {
7545 new_return(12);
7546 }
7547
7548
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7549 {
7550 new_return(13);
7551 }
7552
7553
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7554 {
7555
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7556 {
7557 new_return(14);
7558 }
7559 49152 }
7560
7561
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7562 {
7563 new_return(15);
7564 }
7565
7566
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7567 {
7568 new_return(16);
7569 }
7570
7571
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7572 {
7573 new_return(17);
7574 }
7575
7576
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7577 {
7578 new_return(18);
7579 }
7580
7581
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7582 {
7583 new_return(19);
7584 }
7585
7586
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7587 {
7588 new_return(20);
7589 }
7590
7591
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7592 {
7593 new_return(21);
7594 }
7595
7596
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7597 {
7598 new_return(22);
7599 }
7600
7601
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7602 {
7603 new_return(23);
7604 }
7605
7606
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7607 {
7608 new_return(24);
7609 }
7610
7611
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7612 {
7613 new_return(25);
7614 }
7615
7616
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7617 {
7618 new_return(26);
7619 }
7620
7621
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7622 {
7623 new_return(25);
7624 }
7625
7626
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7627 {
7628 new_return(26);
7629 }
7630
7631
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7632 {
7633 new_return(27);
7634 }
7635
7636 byte disabled[32];
7637 6144 memset(disabled,0,32);
7638
7639
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7640 {
7641
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7642 {
7643 disabled[j/8] |= (1 << (j%8));
7644 }
7645 1572864 }
7646
7647
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7648 {
7649 new_return(28);
7650 }
7651
7652
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7653 {
7654 new_return(29);
7655 }
7656
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7657 {
7658 new_return(30);
7659 }
7660
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7661 {
7662 new_return(31);
7663 }
7664
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7665 {
7666
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7667 {
7668 new_return(32);
7669 }
7670
7671 49152 }
7672
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7673 {
7674
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7675 {
7676
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7677 {
7678 new_return(33);
7679 }
7680 3194880 }
7681 49152 }
7682
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7683 {
7684 new_return(34);
7685 }
7686
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7687 {
7688 new_return(35);
7689 }
7690
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7691 {
7692
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7693 {
7694 new_return(36);
7695 }
7696 49152 }
7697
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7698 {
7699
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7700 {
7701
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7702 {
7703 new_return(37);
7704 }
7705 3194880 }
7706 49152 }
7707
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7708 {
7709 new_return(38);
7710 }
7711
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7712 {
7713
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7714 {
7715 new_return(39);
7716 }
7717 49152 }
7718
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7719 {
7720
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7721 {
7722
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7723 {
7724 new_return(40);
7725 }
7726 3194880 }
7727 49152 }
7728
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7729 {
7730 new_return(41);
7731 }
7732
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7733 {
7734 new_return(42);
7735 }
7736
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7737 {
7738 new_return(43);
7739 }
7740
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7741 {
7742 new_return(44);
7743 }
7744
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7745 {
7746 new_return(45);
7747 }
7748
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7749 new_return(46);
7750
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7751 new_return(47);
7752
7753 // Reserved for z3.
7754
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7755 {
7756
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7757 {
7758
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7759 {
7760 new_return(48);
7761 }
7762 393216 }
7763 49152 }
7764 6144 }
7765
7766
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7767 {
7768 6 section_size=writesize;
7769 6 }
7770 12 }
7771
7772
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7773 {
7774 char ebuf[80];
7775 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7776 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7777 }
7778
7779 6 new_return(0);
7780 }
7781
7782 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7783 {
7784 //these are here to bypass compiler warnings about unused arguments
7785 6 Header=Header;
7786
7787 6 dword section_id=ID_COLORS;
7788 6 dword section_version=V_COLORS;
7789 6 dword section_cversion=CV_COLORS;
7790 6 dword section_size = 0;
7791
7792 //section id
7793
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7794 {
7795 new_return(1);
7796 }
7797
7798
7799 //section version info
7800
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7801 {
7802 new_return(2);
7803 }
7804
7805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7806 {
7807 new_return(3);
7808 }
7809
7810
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7811 {
7812 12 fake_pack_writing=(writecycle==0);
7813
7814 //section size
7815
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7816 {
7817 new_return(4);
7818 }
7819
7820 12 writesize=0;
7821
7822
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7823 {
7824 new_return(5);
7825 }
7826
7827
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7828 {
7829 new_return(6);
7830 }
7831
7832
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7833 {
7834 new_return(7);
7835 }
7836
7837
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7838 {
7839 new_return(8);
7840 }
7841
7842
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7843 {
7844 new_return(9);
7845 }
7846
7847
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7848 {
7849 new_return(10);
7850 }
7851
7852
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7853 {
7854 new_return(11);
7855 }
7856
7857
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7858 {
7859 new_return(12);
7860 }
7861
7862
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7863 {
7864 new_return(13);
7865 }
7866
7867
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
7868 {
7869 new_return(14);
7870 }
7871
7872
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
7873 {
7874 new_return(15);
7875 }
7876
7877
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
7878 {
7879 new_return(16);
7880 }
7881
7882
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
7883 {
7884 new_return(17);
7885 }
7886
7887
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
7888 {
7889 new_return(18);
7890 }
7891
7892
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
7893 {
7894 new_return(19);
7895 }
7896
7897
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
7898 {
7899 new_return(20);
7900 }
7901
7902
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
7903 {
7904 new_return(21);
7905 }
7906
7907
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7908 {
7909 new_return(22);
7910 }
7911
7912
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7913 {
7914 new_return(23);
7915 }
7916
7917
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
7918 {
7919 new_return(24);
7920 }
7921
7922
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7923 {
7924 new_return(31);
7925 }
7926
7927
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
7928 {
7929 new_return(32);
7930 }
7931
7932
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
7933 {
7934 new_return(33);
7935 }
7936
7937
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
7938 {
7939 new_return(34);
7940 }
7941
7942
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
7943 {
7944 new_return(35);
7945 }
7946
7947
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7948 {
7949 new_return(36);
7950 }
7951
7952
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7953 {
7954 new_return(37);
7955 }
7956
7957
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7958 {
7959 new_return(38);
7960 }
7961
7962
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7963 {
7964 new_return(39);
7965 }
7966
7967
7968
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7969 {
7970 6 section_size=writesize;
7971 6 }
7972 12 }
7973
7974
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7975 {
7976 char ebuf[80];
7977 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7978 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7979 }
7980
7981 6 new_return(0);
7982 }
7983
7984 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7985 {
7986 //these are here to bypass compiler warnings about unused arguments
7987 6 Header=Header;
7988
7989 6 dword section_id=ID_ICONS;
7990 6 dword section_version=V_ICONS;
7991 6 dword section_cversion=CV_ICONS;
7992 6 dword section_size = 0;
7993
7994 //section id
7995
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7996 {
7997 new_return(1);
7998 }
7999
8000 //section version info
8001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8002 {
8003 new_return(2);
8004 }
8005
8006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8007 {
8008 new_return(3);
8009 }
8010
8011
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8012 {
8013 12 fake_pack_writing=(writecycle==0);
8014
8015 //section size
8016
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8017 {
8018 new_return(4);
8019 }
8020
8021 12 writesize=0;
8022
8023
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8024 {
8025
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8026 {
8027 new_return(5);
8028 }
8029 48 }
8030
8031
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8032 {
8033 6 section_size=writesize;
8034 6 }
8035 12 }
8036
8037
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8038 {
8039 char ebuf[80];
8040 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8041 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8042 }
8043
8044 6 new_return(0);
8045 }
8046
8047 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8048 {
8049 //these are here to bypass compiler warnings about unused arguments
8050 6 Header=Header;
8051
8052 6 dword section_id=ID_MISC;
8053 6 dword section_version=V_MISC;
8054 6 dword section_cversion=CV_MISC;
8055 6 word shops=count_shops(&QMisc);
8056 6 word infos=count_infos(&QMisc);
8057 6 word warprings=count_warprings(&QMisc);
8058 6 word triforces=8;
8059 6 dword section_size = 0;
8060
8061 //section id
8062
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8063 {
8064 new_return(1);
8065 }
8066
8067
8068 //section version info
8069
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8070 {
8071 new_return(2);
8072 }
8073
8074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8075 {
8076 new_return(3);
8077 }
8078
8079
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8080 {
8081 12 fake_pack_writing=(writecycle==0);
8082
8083 //section size
8084
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8085 {
8086 new_return(4);
8087 }
8088
8089 12 writesize=0;
8090
8091 //shops
8092
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8093 {
8094 new_return(5);
8095 }
8096
8097
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8098 {
8099
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8100 {
8101 new_return(6);
8102 }
8103
8104
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8105 {
8106
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8107 {
8108 new_return(7);
8109 }
8110 384 }
8111
8112
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8113 {
8114
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8115 {
8116 new_return(8);
8117 }
8118 384 }
8119
8120
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8121 {
8122
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8123 {
8124 new_return(9);
8125 }
8126 384 }
8127 128 }
8128
8129 //infos
8130
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8131 {
8132 new_return(10);
8133 }
8134
8135
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8136 {
8137
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8138 {
8139 new_return(11);
8140 }
8141
8142
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8143 {
8144
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8145 {
8146 new_return(12);
8147 }
8148 384 }
8149
8150
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8151 {
8152
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8153 {
8154 new_return(13);
8155 }
8156 384 }
8157 128 }
8158
8159 //warp rings
8160
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8161 {
8162 new_return(14);
8163 }
8164
8165
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8166 {
8167
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8168 {
8169
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8170 {
8171 new_return(15);
8172 }
8173 1296 }
8174
8175
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8176 {
8177
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8178 {
8179 new_return(16);
8180 }
8181 1296 }
8182
8183
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8184 {
8185 new_return(17);
8186 }
8187 144 }
8188
8189 //triforce pieces
8190
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8191 {
8192
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8193 {
8194 new_return(18);
8195 }
8196 96 }
8197
8198 //end string
8199
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8200 {
8201 new_return(19);
8202 }
8203
8204 //V_MISC >= 8
8205
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8206 {
8207
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8208 {
8209
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8210 {
8211 new_return(20);
8212 }
8213 384 }
8214 128 }
8215 //V_MISC >= 9
8216
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8217 {
8218
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8219 new_return(21);
8220 384 }
8221
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8222 {
8223
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8224
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(0,f))
8225 new_return(22);
8226 384 }
8227 //V_MISC >= 11
8228
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8229 new_return(23);
8230
8231 //V_MISC >= 12
8232
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8233 {
8234
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8235 new_return(24);
8236 3072 }
8237
8238 //V_MISC >= 13
8239
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8240 {
8241 768 bottletype* bt = &(QMisc.bottle_types[q]);
8242
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8243 new_return(25);
8244
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8245 {
8246
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8247 new_return(25);
8248
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8249 new_return(25);
8250 2304 }
8251
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8252 new_return(25);
8253
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8254 new_return(25);
8255 768 }
8256
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8257 {
8258 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8259
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8260 new_return(26);
8261
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8262 {
8263
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8264 new_return(26);
8265
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8266 new_return(26);
8267
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8268 new_return(26);
8269
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8270 new_return(26);
8271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8272 new_return(26);
8273 9216 }
8274 3072 }
8275
8276 //V_MISC >= 14
8277
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8278 {
8279
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8280 new_return(27);
8281 3072 }
8282
8283
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8284 {
8285 6 section_size=writesize;
8286 6 }
8287 12 }
8288
8289
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8290 {
8291 char ebuf[80];
8292 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8293 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8294 }
8295
8296 6 new_return(0);
8297 }
8298
8299 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8300 {
8301 //these are here to bypass compiler warnings about unused arguments
8302 6 Header=Header;
8303
8304 6 dword section_id=ID_ITEMS;
8305 6 dword section_version=V_ITEMS;
8306 6 dword section_cversion=CV_ITEMS;
8307 // dword section_size=0;
8308 6 dword section_size = 0;
8309
8310 //section id
8311
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8312 {
8313 new_return(1);
8314 }
8315
8316 //section version info
8317
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8318 {
8319 new_return(2);
8320 }
8321
8322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8323 {
8324 new_return(3);
8325 }
8326
8327
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8328 {
8329 12 fake_pack_writing=(writecycle==0);
8330
8331 //section size
8332
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8333 {
8334 new_return(4);
8335 }
8336
8337 12 writesize=0;
8338
8339 //finally... section data
8340
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8341 {
8342 new_return(5);
8343 }
8344
8345
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8346 {
8347
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8348 {
8349 new_return(5);
8350 }
8351 3072 }
8352
8353
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8354 {
8355
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8356 {
8357 new_return(6);
8358 }
8359
8360
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8361 {
8362 new_return(7);
8363 }
8364
8365
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8366 {
8367 new_return(8);
8368 }
8369
8370
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8371 {
8372 new_return(9);
8373 }
8374
8375
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8376 {
8377 new_return(10);
8378 }
8379
8380
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8381 {
8382 new_return(11);
8383 }
8384
8385
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8386 {
8387 new_return(12);
8388 }
8389
8390
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8391 {
8392 new_return(13);
8393 }
8394
8395
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8396 {
8397 new_return(14);
8398 }
8399
8400
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8401 {
8402 new_return(14);
8403 }
8404
8405
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8406 {
8407 new_return(15);
8408 }
8409
8410
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8411 {
8412 new_return(16);
8413 }
8414
8415
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8416 {
8417 new_return(17);
8418 }
8419
8420
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8421 {
8422 new_return(18);
8423 }
8424
8425
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8426 {
8427 new_return(19);
8428 }
8429
8430
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8431 {
8432 new_return(21);
8433 }
8434
8435
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8436 {
8437 new_return(22);
8438 }
8439
8440
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8441 {
8442 new_return(23);
8443 }
8444
8445
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8446 {
8447
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8448 {
8449 new_return(24);
8450 }
8451 24576 }
8452
8453
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8454 {
8455
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(0,f))
8456 {
8457 new_return(25);
8458 }
8459 6144 }
8460
8461
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8462 {
8463 new_return(26);
8464 }
8465
8466
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8467 {
8468 new_return(27);
8469 }
8470
8471
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8472 {
8473 new_return(28);
8474 }
8475
8476
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8477 {
8478 new_return(29);
8479 }
8480
8481
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8482 {
8483 new_return(30);
8484 }
8485
8486
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8487 {
8488 new_return(31);
8489 }
8490
8491
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8492 {
8493 new_return(32);
8494 }
8495
8496
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8497 {
8498 new_return(33);
8499 }
8500
8501
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8502 {
8503 new_return(34);
8504 }
8505
8506
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8507 {
8508 new_return(35);
8509 }
8510
8511
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8512 {
8513 new_return(36);
8514 }
8515
8516
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8517 {
8518 new_return(37);
8519 }
8520
8521
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8522 {
8523 new_return(38);
8524 }
8525
8526
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8527 {
8528
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8529 {
8530 new_return(39);
8531 }
8532 6144 }
8533
8534
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8535 {
8536 new_return(40);
8537 }
8538
8539
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8540 {
8541 new_return(41);
8542 }
8543
8544
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8545 {
8546 new_return(42);
8547 }
8548
8549
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8550 {
8551 new_return(43);
8552 }
8553
8554
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8555 {
8556 new_return(44);
8557 }
8558
8559
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8560 {
8561 new_return(45);
8562 }
8563
8564
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8565 {
8566 new_return(46);
8567 }
8568
8569
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8570 {
8571 new_return(47);
8572 }
8573
8574
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8575 {
8576 new_return(48);
8577 }
8578
8579
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8580 {
8581 new_return(48);
8582 }
8583
8584 //New itemdata vars -Z
8585 //! version 27
8586
8587
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8588 {
8589 new_return(49);
8590 }
8591
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8592 {
8593 new_return(50);
8594 }
8595
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8596 {
8597 new_return(51);
8598 }
8599
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8600 {
8601 new_return(52);
8602 }
8603
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8604
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8605 {
8606 new_return(53);
8607 }
8608 30720 }
8609 //version 28
8610
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8611 {
8612 new_return(54);
8613 }
8614
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8615 {
8616
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8617 {
8618 new_return(55);
8619 }
8620 24576 }
8621
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8622 {
8623
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(0,f))
8624 {
8625 new_return(56);
8626 }
8627 6144 }
8628
8629
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8630 {
8631 new_return(57);
8632 }
8633
8634
8635
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8636 {
8637 new_return(58);
8638 }
8639
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8640 {
8641 new_return(59);
8642 }
8643
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8644 {
8645 new_return(60);
8646 }
8647
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8648 {
8649 new_return(61);
8650 }
8651
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8652 {
8653 new_return(62);
8654 }
8655
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8656 {
8657 new_return(63);
8658 }
8659
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8660 {
8661 new_return(64);
8662 }
8663
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8664 {
8665 new_return(65);
8666 }
8667
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8668 {
8669 new_return(66);
8670 }
8671
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8672 {
8673 new_return(67);
8674 }
8675
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8676 {
8677 new_return(68);
8678 }
8679
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8680 {
8681 new_return(69);
8682 }
8683
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8684 {
8685 new_return(70);
8686 }
8687
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8688 {
8689 new_return(71);
8690 }
8691
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8692 {
8693 new_return(72);
8694 }
8695
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8696 {
8697 new_return(73);
8698 }
8699
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8700 {
8701
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8702 {
8703 new_return(74);
8704 }
8705 6144 }
8706
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8707 {
8708 new_return(75);
8709 }
8710
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8711 {
8712 new_return(76);
8713 }
8714
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8715 {
8716 new_return(77);
8717 }
8718
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8719 {
8720 new_return(78);
8721 }
8722
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8723 {
8724 new_return(79);
8725 }
8726
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8727 {
8728 new_return(80);
8729 }
8730
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8731 {
8732 new_return(81);
8733 }
8734
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8735 {
8736 new_return(82);
8737 }
8738
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8739 {
8740 new_return(83);
8741 }
8742
8743
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8744 {
8745
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8746 {
8747 new_return(84);
8748 }
8749 6144 }
8750
8751 //InitD[] labels
8752
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8753 {
8754
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8755 {
8756
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8757 {
8758 new_return(85);
8759 }
8760 1597440 }
8761
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8762 {
8763
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8764 {
8765 new_return(86);
8766 }
8767 1597440 }
8768
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8769 {
8770
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8771 {
8772 new_return(87);
8773 }
8774 1597440 }
8775
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8776 {
8777 new_return(88);
8778 }
8779 24576 }
8780
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8781 {
8782
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(0,f))
8783 {
8784 new_return(89);
8785 }
8786
8787 6144 }
8788
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8789 {
8790 new_return(90);
8791 }
8792
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8793 {
8794 new_return(91);
8795 }
8796
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8797
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8798 new_return(92);
8799
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < WPNSPR_MAX; ++q)
8800 {
8801
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8802 new_return(93);
8803
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8804 new_return(94);
8805 15360 }
8806 3072 }
8807
8808
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8809 {
8810 6 section_size=writesize;
8811 6 }
8812 12 }
8813
8814
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8815 {
8816 char ebuf[80];
8817 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8818 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8819 }
8820
8821 6 new_return(0);
8822 }
8823
8824 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8825 {
8826 //these are here to bypass compiler warnings about unused arguments
8827 6 Header=Header;
8828
8829 6 dword section_id=ID_WEAPONS;
8830 6 dword section_version=V_WEAPONS;
8831 6 dword section_cversion=CV_WEAPONS;
8832 6 dword section_size = 0;
8833
8834 //section id
8835
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8836 {
8837 new_return(1);
8838 }
8839
8840 //section version info
8841
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8842 {
8843 new_return(2);
8844 }
8845
8846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8847 {
8848 new_return(3);
8849 }
8850
8851
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8852 {
8853 12 fake_pack_writing=(writecycle==0);
8854
8855 //section size
8856
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8857 {
8858 new_return(4);
8859 }
8860
8861 12 writesize=0;
8862
8863 //finally... section data
8864
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8865 {
8866 new_return(5);
8867 }
8868
8869
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8870 {
8871
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
8872 {
8873 new_return(5);
8874 }
8875 3072 }
8876
8877
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8878 {
8879
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
8880 {
8881 new_return(7);
8882 }
8883
8884
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
8885 {
8886 new_return(8);
8887 }
8888
8889
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
8890 {
8891 new_return(9);
8892 }
8893
8894
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
8895 {
8896 new_return(10);
8897 }
8898
8899
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
8900 {
8901 new_return(11);
8902 }
8903
8904
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
8905 {
8906 new_return(12);
8907 }
8908
8909
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
8910 {
8911 new_return(12);
8912 }
8913 3072 }
8914
8915
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8916 {
8917 6 section_size=writesize;
8918 6 }
8919 12 }
8920
8921
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8922 {
8923 char ebuf[80];
8924 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8925 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8926 }
8927
8928 6 new_return(0);
8929 }
8930
8931 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8932 {
8933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8934 return qe_invalid;
8935
8936 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8937 4080 bool is_0x80_screen = j >= 0x80;
8938
8939
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
8940 return qe_invalid;
8941
2/2
✓ Branch 0 taken 2080 times.
✓ Branch 1 taken 2000 times.
4080 if(!(screen.valid & mVALID))
8942 2000 return qe_OK;
8943 //Calculate what needs writing
8944 2080 uint32_t scr_has_flags = 0;
8945
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2078 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2080 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8946
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8947 2080 scr_has_flags |= SCRHAS_ROOMDATA;
8948
7/8
✓ Branch 0 taken 1798 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1678 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2080 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8949 290 scr_has_flags |= SCRHAS_ITEM;
8950
3/4
✓ Branch 0 taken 2062 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2062 times.
2080 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8951 18 scr_has_flags |= SCRHAS_TWARP;
8952
2/2
✓ Branch 0 taken 1894 times.
✓ Branch 1 taken 7746 times.
9640 else for(auto q = 0; q < 4; ++q)
8953 {
8954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7578 times.
15324 if(screen.tilewarptype[q]
8955
2/2
✓ Branch 0 taken 7580 times.
✓ Branch 1 taken 166 times.
7746 || screen.tilewarpdmap[q]
8956
2/2
✓ Branch 0 taken 7578 times.
✓ Branch 1 taken 2 times.
7580 || screen.tilewarpscr[q])
8957 {
8958 168 scr_has_flags |= SCRHAS_TWARP;
8959 168 break;
8960 }
8961 7578 }
8962
3/4
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2074 times.
2080 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8963
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 2 times.
2076 || screen.sidewarpoverlayflags)
8964 6 scr_has_flags |= SCRHAS_SWARP;
8965
2/2
✓ Branch 0 taken 634 times.
✓ Branch 1 taken 3976 times.
4610 else for(auto q = 0; q < 4; ++q)
8966 {
8967
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2536 times.
6520 if(screen.sidewarptype[q] != wtSCROLL
8968
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 1424 times.
3976 || screen.sidewarpdmap[q]
8969
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 8 times.
2552 || screen.sidewarpscr[q])
8970 {
8971 1440 scr_has_flags |= SCRHAS_SWARP;
8972 1440 break;
8973 }
8974 2536 }
8975
3/4
✓ Branch 0 taken 2036 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2036 times.
2080 if(screen.warparrivalx || screen.warparrivaly)
8976 44 scr_has_flags |= SCRHAS_WARPRET;
8977
2/2
✓ Branch 0 taken 1448 times.
✓ Branch 1 taken 6380 times.
7828 else for(auto q = 0; q < 4; ++q)
8978 {
8979
3/4
✓ Branch 0 taken 5792 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5792 times.
6380 if(screen.warpreturnx[q] || screen.warpreturny[q])
8980 {
8981 588 scr_has_flags |= SCRHAS_WARPRET;
8982 588 break;
8983 }
8984 5792 }
8985
8986
2/4
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2080 times.
2080 if(screen.hidelayers || screen.hidescriptlayers)
8987 scr_has_flags |= SCRHAS_LAYERS;
8988
2/2
✓ Branch 0 taken 1888 times.
✓ Branch 1 taken 11536 times.
13424 else for(auto q = 0; q < 6; ++q)
8989 {
8990
4/4
✓ Branch 0 taken 11354 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11344 times.
11536 if(screen.layermap[q] || screen.layerscreen[q]
8991
1/2
✓ Branch 0 taken 11354 times.
✗ Branch 1 not taken.
11354 || screen.layeropacity[q]!=255)
8992 {
8993 192 scr_has_flags |= SCRHAS_LAYERS;
8994 192 break;
8995 }
8996 11344 }
8997
8998
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2076 times.
2080 if(screen.exitdir)
8999 4 scr_has_flags |= SCRHAS_MAZE;
9000
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 8304 times.
10380 else for(auto q = 0; q < 4; ++q)
9001 {
9002
1/2
✓ Branch 0 taken 8304 times.
✗ Branch 1 not taken.
8304 if(screen.path[q])
9003 {
9004 scr_has_flags |= SCRHAS_MAZE;
9005 break;
9006 }
9007 8304 }
9008
9009
4/4
✓ Branch 0 taken 1846 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 750 times.
3068 if(screen.door_combo_set || screen.stairx
9010
3/4
✓ Branch 0 taken 1818 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1818 times.
✗ Branch 3 not taken.
1846 || screen.stairy || screen.undercombo
9011
2/2
✓ Branch 0 taken 988 times.
✓ Branch 1 taken 830 times.
1818 || screen.undercset)
9012 1330 scr_has_flags |= SCRHAS_D_S_U;
9013
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 810 times.
830 else for(auto q = 0; q < 4; ++q)
9014 {
9015
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 730 times.
810 if(screen.door[q] != dNONE)
9016 {
9017 730 scr_has_flags |= SCRHAS_D_S_U;
9018 730 break;
9019 }
9020 80 }
9021
9022
2/2
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 260 times.
3536 if(screen.flags || screen.flags2
9023
4/4
✓ Branch 0 taken 1734 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1700 times.
✓ Branch 3 taken 34 times.
1820 || screen.flags3 || screen.flags4
9024
4/4
✓ Branch 0 taken 1686 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1672 times.
✓ Branch 3 taken 14 times.
1700 || screen.flags5 || screen.flags6
9025
4/4
✓ Branch 0 taken 1464 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1456 times.
✓ Branch 3 taken 8 times.
1672 || screen.flags7 || screen.flags8
9026
2/4
✓ Branch 0 taken 1456 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1456 times.
✗ Branch 3 not taken.
1456 || screen.flags9 || screen.flags10
9027
1/2
✓ Branch 0 taken 1456 times.
✗ Branch 1 not taken.
1456 || screen.enemyflags)
9028 2080 scr_has_flags |= SCRHAS_FLAGS;
9029
9030
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2030 times.
2080 if(screen.pattern)
9031 50 scr_has_flags |= SCRHAS_ENEMY;
9032
2/2
✓ Branch 0 taken 1390 times.
✓ Branch 1 taken 14540 times.
15930 else for(auto q = 0; q < 10; ++q)
9033 {
9034
2/2
✓ Branch 0 taken 13900 times.
✓ Branch 1 taken 640 times.
14540 if(screen.enemy[q])
9035 {
9036 640 scr_has_flags |= SCRHAS_ENEMY;
9037 640 break;
9038 }
9039 13900 }
9040
9041
2/4
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2074 times.
4154 if(screen.noreset || screen.nocarry
9042
3/4
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2074 times.
✓ Branch 3 taken 6 times.
2080 || screen.nextmap || screen.nextscr)
9043 6 scr_has_flags |= SCRHAS_CARRY;
9044
9045
3/4
✓ Branch 0 taken 2060 times.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2060 times.
2080 if(screen.script || screen.preloadscript)
9046 20 scr_has_flags |= SCRHAS_SCRIPT;
9047
2/2
✓ Branch 0 taken 2060 times.
✓ Branch 1 taken 16480 times.
18540 else for(auto q = 0; q < 8; ++q)
9048 {
9049
1/2
✓ Branch 0 taken 16480 times.
✗ Branch 1 not taken.
16480 if(screen.screeninitd[q])
9050 {
9051 scr_has_flags |= SCRHAS_SCRIPT;
9052 break;
9053 }
9054 16480 }
9055
9056
2/2
✓ Branch 0 taken 756 times.
✓ Branch 1 taken 99096 times.
99852 for(auto q = 0; q < 128; ++q)
9057 {
9058
1/2
✓ Branch 0 taken 97772 times.
✗ Branch 1 not taken.
196868 if(screen.secretcombo[q]
9059
2/2
✓ Branch 0 taken 97774 times.
✓ Branch 1 taken 1322 times.
99096 || screen.secretcset[q]
9060
2/2
✓ Branch 0 taken 97772 times.
✓ Branch 1 taken 2 times.
97774 || screen.secretflag[q])
9061 {
9062 1324 scr_has_flags |= SCRHAS_SECRETS;
9063 1324 break;
9064 }
9065 97772 }
9066
9067
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40226 times.
40398 for(auto q = 0; q < 176; ++q)
9068 {
9069
4/4
✓ Branch 0 taken 38410 times.
✓ Branch 1 taken 1816 times.
✓ Branch 2 taken 38318 times.
✓ Branch 3 taken 2 times.
40226 if(screen.data[q] || screen.cset[q]
9070
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 90 times.
38410 || screen.sflag[q])
9071 {
9072 1908 scr_has_flags |= SCRHAS_COMBOFLAG;
9073 1908 break;
9074 }
9075 38318 }
9076
9077
2/2
✓ Branch 0 taken 784 times.
✓ Branch 1 taken 1296 times.
2080 if(screen.color || screen.csensitive != 1
9078
3/4
✓ Branch 0 taken 784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 750 times.
✓ Branch 3 taken 34 times.
784 || screen.oceansfx || screen.bosssfx
9079
2/4
✓ Branch 0 taken 750 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 750 times.
750 || screen.secretsfx || screen.holdupsfx
9080 || screen.timedwarptics || screen.screen_midi != -1
9081 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9082 2080 scr_has_flags |= SCRHAS_MISC;
9083
9084
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputl(scr_has_flags,f))
9085 return qe_invalid;
9086
9087 //Write stuff
9088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2080 times.
2080 if(scr_has_flags & SCRHAS_ROOMDATA)
9089 {
9090
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.guy,f))
9091 return qe_invalid;
9092
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputl(screen.guytile,f))
9093 return qe_invalid;
9094
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.guycs,f))
9095 return qe_invalid;
9096
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputw(screen.roomflags,f))
9097 return qe_invalid;
9098
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputw(screen.str,f))
9099 return qe_invalid;
9100
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.room,f))
9101 return qe_invalid;
9102
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputw(screen.catchall,f))
9103 return qe_invalid;
9104 2080 }
9105
2/2
✓ Branch 0 taken 1790 times.
✓ Branch 1 taken 290 times.
2080 if(scr_has_flags & SCRHAS_ITEM)
9106 {
9107
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9108 return qe_invalid;
9109
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9110 return qe_invalid;
9111
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9112 return qe_invalid;
9113
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9114 return qe_invalid;
9115 290 }
9116
2/2
✓ Branch 0 taken 580 times.
✓ Branch 1 taken 1500 times.
2080 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9117 {
9118
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9119 return qe_invalid;
9120 1500 }
9121
2/2
✓ Branch 0 taken 1894 times.
✓ Branch 1 taken 186 times.
2080 if(scr_has_flags & SCRHAS_TWARP)
9122 {
9123
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9124 {
9125
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9126 return qe_invalid;
9127 744 }
9128
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9129 {
9130
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9131 return qe_invalid;
9132 744 }
9133
9134
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9135 {
9136
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9137 return qe_invalid;
9138 744 }
9139
9140
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9141 return qe_invalid;
9142 186 }
9143
2/2
✓ Branch 0 taken 634 times.
✓ Branch 1 taken 1446 times.
2080 if(scr_has_flags & SCRHAS_SWARP)
9144 {
9145
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9146 {
9147
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9148 return qe_invalid;
9149 5784 }
9150
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9151 {
9152
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9153 return qe_invalid;
9154 5784 }
9155
9156
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9157 {
9158
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9159 return qe_invalid;
9160 5784 }
9161
9162
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9163 return qe_invalid;
9164
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9165 return qe_invalid;
9166 1446 }
9167
2/2
✓ Branch 0 taken 1448 times.
✓ Branch 1 taken 632 times.
2080 if(scr_has_flags & SCRHAS_WARPRET)
9168 {
9169
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9170 {
9171
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9172 return qe_invalid;
9173 2528 }
9174
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9175 {
9176
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9177 return qe_invalid;
9178 2528 }
9179
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9180 return qe_invalid;
9181
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9182 return qe_invalid;
9183 632 }
9184
2/2
✓ Branch 0 taken 1888 times.
✓ Branch 1 taken 192 times.
2080 if(scr_has_flags & SCRHAS_LAYERS)
9185 {
9186
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9187 {
9188
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9189 return qe_invalid;
9190 1152 }
9191
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9192 {
9193
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9194 return qe_invalid;
9195 1152 }
9196
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9197 {
9198
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9199 return qe_invalid;
9200 1152 }
9201
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9202 return qe_invalid;
9203
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9204 return qe_invalid;
9205 192 }
9206
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 4 times.
2080 if(scr_has_flags & SCRHAS_MAZE)
9207 {
9208
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9209 {
9210
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9211 return qe_invalid;
9212 16 }
9213
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9214 return qe_invalid;
9215 4 }
9216
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2060 times.
2080 if(scr_has_flags & SCRHAS_D_S_U)
9217 {
9218
1/2
✓ Branch 0 taken 2060 times.
✗ Branch 1 not taken.
2060 if(!p_iputw(screen.door_combo_set,f))
9219 return qe_invalid;
9220
2/2
✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 2060 times.
10300 for(int32_t k=0; k<4; k++)
9221 {
9222
1/2
✓ Branch 0 taken 8240 times.
✗ Branch 1 not taken.
8240 if(!p_putc(screen.door[k],f))
9223 return qe_invalid;
9224 8240 }
9225
1/2
✓ Branch 0 taken 2060 times.
✗ Branch 1 not taken.
2060 if(!p_putc(screen.stairx,f))
9226 return qe_invalid;
9227
1/2
✓ Branch 0 taken 2060 times.
✗ Branch 1 not taken.
2060 if(!p_putc(screen.stairy,f))
9228 return qe_invalid;
9229
1/2
✓ Branch 0 taken 2060 times.
✗ Branch 1 not taken.
2060 if(!p_iputw(screen.undercombo,f))
9230 return qe_invalid;
9231
1/2
✓ Branch 0 taken 2060 times.
✗ Branch 1 not taken.
2060 if(!p_putc(screen.undercset,f))
9232 return qe_invalid;
9233 2060 }
9234
2/2
✓ Branch 0 taken 1334 times.
✓ Branch 1 taken 746 times.
2080 if(scr_has_flags & SCRHAS_FLAGS)
9235 {
9236
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9237 return qe_invalid;
9238
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9239 return qe_invalid;
9240
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9241 return qe_invalid;
9242
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9243 return qe_invalid;
9244
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9245 return qe_invalid;
9246
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9247 return qe_invalid;
9248
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9249 return qe_invalid;
9250
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9251 return qe_invalid;
9252
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9253 return qe_invalid;
9254
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9255 return qe_invalid;
9256
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9257 return qe_invalid;
9258 746 }
9259
2/2
✓ Branch 0 taken 1390 times.
✓ Branch 1 taken 690 times.
2080 if(scr_has_flags & SCRHAS_ENEMY)
9260 {
9261
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9262 {
9263
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9264 return qe_invalid;
9265 6900 }
9266
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9267 return qe_invalid;
9268 690 }
9269
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 6 times.
2080 if(scr_has_flags & SCRHAS_CARRY)
9270 {
9271
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9272 return qe_invalid;
9273
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9274 return qe_invalid;
9275
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9276 return qe_invalid;
9277
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9278 return qe_invalid;
9279 6 }
9280
2/2
✓ Branch 0 taken 2060 times.
✓ Branch 1 taken 20 times.
2080 if(scr_has_flags & SCRHAS_SCRIPT)
9281 {
9282
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if(!p_iputw(screen.script,f))
9283 return qe_invalid;
9284
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if(!p_putc(screen.preloadscript,f))
9285 return qe_invalid;
9286
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 20 times.
180 for ( int32_t q = 0; q < 8; q++ )
9287 {
9288
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!p_iputl(screen.screeninitd[q],f))
9289 return qe_invalid;
9290 160 }
9291 20 }
9292
2/2
✓ Branch 0 taken 756 times.
✓ Branch 1 taken 1324 times.
2080 if(scr_has_flags & SCRHAS_SECRETS)
9293 {
9294
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9295 {
9296
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9297 return qe_invalid;
9298 169472 }
9299
9300
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9301 {
9302
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9303 return qe_invalid;
9304 169472 }
9305
9306
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9307 {
9308
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9309 return qe_invalid;
9310 169472 }
9311 1324 }
9312
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1908 times.
2080 if(scr_has_flags & SCRHAS_COMBOFLAG)
9313 {
9314
2/2
✓ Branch 0 taken 335808 times.
✓ Branch 1 taken 1908 times.
337716 for(int32_t k=0; k<176; ++k)
9315 {
9316
1/2
✓ Branch 0 taken 335808 times.
✗ Branch 1 not taken.
335808 if(!p_iputw(screen.data[k],f))
9317 return qe_invalid;
9318 335808 }
9319
2/2
✓ Branch 0 taken 335808 times.
✓ Branch 1 taken 1908 times.
337716 for(int32_t k=0; k<176; ++k)
9320 {
9321
1/2
✓ Branch 0 taken 335808 times.
✗ Branch 1 not taken.
335808 if(!p_putc(screen.sflag[k],f))
9322 return qe_invalid;
9323 335808 }
9324
2/2
✓ Branch 0 taken 335808 times.
✓ Branch 1 taken 1908 times.
337716 for(int32_t k=0; k<176; ++k)
9325 {
9326
1/2
✓ Branch 0 taken 335808 times.
✗ Branch 1 not taken.
335808 if(!p_putc(screen.cset[k],f))
9327 return qe_invalid;
9328 335808 }
9329 1908 }
9330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2080 times.
2080 if(scr_has_flags & SCRHAS_MISC)
9331 {
9332
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputw(screen.color,f))
9333 return qe_invalid;
9334
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.csensitive,f))
9335 return qe_invalid;
9336
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.oceansfx,f))
9337 return qe_invalid;
9338
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.bosssfx,f))
9339 return qe_invalid;
9340
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.secretsfx,f))
9341 return qe_invalid;
9342
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.holdupsfx,f))
9343 return qe_invalid;
9344
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputw(screen.timedwarptics,f))
9345 return qe_invalid;
9346
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputw(screen.screen_midi,f))
9347 return qe_invalid;
9348
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.lens_layer,f))
9349 return qe_invalid;
9350
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.lens_show,f))
9351 return qe_invalid;
9352
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putc(screen.lens_hide,f))
9353 return qe_invalid;
9354 2080 }
9355
9356 2080 dword numffc = screen.numFFC();
9357
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_iputw(numffc,f))
9358 return qe_invalid;
9359
2/2
✓ Branch 0 taken 45294 times.
✓ Branch 1 taken 2080 times.
47374 for(int32_t k=0; k<numffc; ++k)
9360 {
9361 45294 ffcdata const& tempffc = screen.ffcs[k];
9362
9363
1/2
✓ Branch 0 taken 45294 times.
✗ Branch 1 not taken.
45294 if(!p_iputw(tempffc.data,f))
9364 return qe_invalid;
9365
9366
2/2
✓ Branch 0 taken 44208 times.
✓ Branch 1 taken 1086 times.
45294 if(!tempffc.data) //don't save the rest of the ffc
9367 44208 continue;
9368
9369
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_putc(tempffc.cset,f))
9370 return qe_invalid;
9371
9372
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputw(tempffc.delay,f))
9373 return qe_invalid;
9374
9375
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputzf(tempffc.x,f))
9376 return qe_invalid;
9377
9378
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputzf(tempffc.y,f))
9379 return qe_invalid;
9380
9381
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputzf(tempffc.vx,f))
9382 return qe_invalid;
9383
9384
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputzf(tempffc.vy,f))
9385 return qe_invalid;
9386
9387
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputzf(tempffc.ax,f))
9388 return qe_invalid;
9389
9390
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputzf(tempffc.ay,f))
9391 return qe_invalid;
9392
9393
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_putc(tempffc.link,f))
9394 return qe_invalid;
9395
9396
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputl(tempffc.hit_width,f))
9397 return qe_invalid;
9398
9399
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputl(tempffc.hit_height,f))
9400 return qe_invalid;
9401
9402
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_putc(tempffc.txsz,f))
9403 return qe_invalid;
9404
9405
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_putc(tempffc.tysz,f))
9406 return qe_invalid;
9407
9408
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputl(tempffc.flags,f))
9409 return qe_invalid;
9410
9411
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_iputw(tempffc.script,f))
9412 return qe_invalid;
9413
9414
2/2
✓ Branch 0 taken 8688 times.
✓ Branch 1 taken 1086 times.
9774 for(auto q = 0; q < 8; ++q)
9415 {
9416
1/2
✓ Branch 0 taken 8688 times.
✗ Branch 1 not taken.
8688 if(!p_iputl(tempffc.initd[q],f))
9417 return qe_invalid;
9418 8688 }
9419
9420
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_putc(0,f))
9421 return qe_invalid;
9422
1/2
✓ Branch 0 taken 1086 times.
✗ Branch 1 not taken.
1086 if(!p_putc(0,f))
9423 return qe_invalid;
9424 1086 }
9425
9426
1/2
✓ Branch 0 taken 2080 times.
✗ Branch 1 not taken.
2080 if(!p_putlstr(screen.usr_notes, f))
9427 return qe_invalid;
9428
9429 2080 return qe_OK;
9430 4080 }
9431
9432 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9433 {
9434 6 dword section_id=ID_MAPS;
9435 6 dword section_version=V_MAPS;
9436 6 dword section_cversion=CV_MAPS;
9437 6 dword section_size = 0;
9438
9439 //section id
9440
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9441 {
9442 new_return(1);
9443 }
9444
9445 //section version info
9446
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9447 {
9448 new_return(2);
9449 }
9450
9451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9452 {
9453 new_return(3);
9454 }
9455
9456
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9457 {
9458 12 fake_pack_writing=(writecycle==0);
9459
9460 //section size
9461
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9462 {
9463 new_return(4);
9464 }
9465
9466 12 writesize=0;
9467
9468
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9469 {
9470 new_return(5);
9471 }
9472 12 map_autolayers.resize(map_count*6);
9473
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9474 {
9475 30 byte valid = 0;
9476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9477 {
9478
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9479 break;
9480 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9481
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9482 {
9483 30 valid = 1;
9484 30 break;
9485 }
9486 210 }
9487
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9488 {
9489 new_return(6);
9490 }
9491
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9492
9493 { //per-map info
9494
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9495 {
9496 180 size_t ind = i*6+q;
9497
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9498 new_return(7);
9499 180 }
9500 }
9501
9502
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9503 4080 writemapscreen(f,i,j);
9504 30 }
9505
9506
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9507 {
9508 6 section_size=writesize;
9509 6 }
9510 12 }
9511
9512
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9513 {
9514 char ebuf[80];
9515 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9516 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9517 }
9518
9519 6 new_return(0);
9520 }
9521
9522 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9523 {
9524 //Check what needs writing
9525 byte combo_has_flags = 0;
9526 383638 for(auto q = 0; q < 8; ++q)
9527 {
9528 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9529 383638 || (q < 4 && tmp_cmb.attributes[q]))
9530 {
9531 combo_has_flags |= CHAS_ATTRIB;
9532 break;
9533 }
9534 383638 }
9535
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9536
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9537
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9538
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9539
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9540
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9541
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9542
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9543
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9544
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9545
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9546
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9547
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9548
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9549
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9550
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9551
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9552
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9553
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9554
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9555
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9556
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9557
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9558
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9559 96892 combo_has_flags |= CHAS_TRIG;
9560
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9561
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9562 combo_has_flags |= CHAS_TRIG;
9563
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9564 193592 combo_has_flags |= CHAS_FLAG;
9565
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9566
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9567
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9568 196334 combo_has_flags |= CHAS_ANIM;
9569
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9570 70224 combo_has_flags |= CHAS_SCRIPT;
9571
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9572 {
9573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9574 {
9575 combo_has_flags |= CHAS_SCRIPT;
9576 break;
9577 }
9578 776032 }
9579
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9580
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9581 185268 combo_has_flags |= CHAS_BASIC;
9582
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9583
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9584
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9585
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9586
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9587
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9588
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9589 131132 combo_has_flags |= CHAS_LIFT;
9590
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
226464 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9591
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9592
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9593
6/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 95332 times.
✓ Branch 3 taken 1664 times.
✓ Branch 4 taken 95332 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 95332 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 95332 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9594
2/4
✓ Branch 0 taken 95332 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 95332 times.
✗ Branch 3 not taken.
95332 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning)
9595 131132 combo_has_flags |= CHAS_GENERAL;
9596
9597
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9598 {
9599 34128 return 50;
9600 }
9601
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9602 //Write the combo
9603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9604 {
9605
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9606 return 6;
9607
9608
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9609 return 7;
9610
9611
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9612 return 8;
9613
9614
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9615 return 9;
9616
9617
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9618 return 15;
9619
9620
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9621 return 10;
9622 44820 }
9623
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9624 {
9625 p_putcstr(tmp_cmb.label, f);
9626
9627 if(!p_iputw(tmp_cmb.script,f))
9628 return 26;
9629 for ( int32_t q = 0; q < 8; q++ )
9630 if(!p_iputl(tmp_cmb.initd[q],f))
9631 return 27;
9632 }
9633
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9634 {
9635
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9636 return 11;
9637
9638
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9639 return 12;
9640
9641
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9642 return 13;
9643
9644
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9645 return 14;
9646
9647
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9648 return 16;
9649
9650
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9651 return 18;
9652
9653
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9654 return 19;
9655 17346 }
9656
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9657 {
9658
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9660 return 20;
9661
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9663 return 25;
9664
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9666 return 32;
9667 2268 }
9668
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9669 {
9670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9671 return 21;
9672
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9673 return 33;
9674 184 }
9675
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9676 {
9677
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9679 return 22;
9680
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9681 return 23;
9682
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9683 return 34;
9684
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9685 return 35;
9686
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9687 return 36;
9688
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9689 return 37;
9690
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9691 return 38;
9692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9693 return 39;
9694
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9695 return 40;
9696
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9697 return 41;
9698
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9699 return 42;
9700
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9701 return 43;
9702
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9703 return 44;
9704
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9705 return 45;
9706
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9707 return 46;
9708
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9709 return 47;
9710
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9711 return 48;
9712
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9713 return 49;
9714
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9715 return 50;
9716
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9717 return 51;
9718
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9719 return 52;
9720
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9721 return 53;
9722
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9723 return 69;
9724
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9725 return 70;
9726
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9727 return 71;
9728
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9729 return 72;
9730
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9731 return 76;
9732
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9733 return 77;
9734
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9735 return 89;
9736
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9737 return 90;
9738
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9739 return 91;
9740
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9741 return 92;
9742
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9743
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_iputw(tmp_cmb.trigtint[q],f))
9744 return 93;
9745
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9746 return 94;
9747
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9748 return 95;
9749
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9750 return 96;
9751
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9752 return 97;
9753
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9754 return 98;
9755
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9756 return 99;
9757
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9758 return 100;
9759
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9760 return 101;
9761
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9762 return 102;
9763
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9764 return 103;
9765 168 }
9766
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9767 {
9768
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9769 return 54;
9770
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9771 return 55;
9772
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9773 return 56;
9774
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9775 return 57;
9776
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9777 return 58;
9778
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9779 return 59;
9780
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9781 return 60;
9782
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9783 return 61;
9784
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9785 return 62;
9786
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9787 return 63;
9788
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9789 return 64;
9790
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9791 return 65;
9792
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9793 return 66;
9794
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9795 return 67;
9796
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9797 return 68;
9798
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9799 return 78;
9800 8 }
9801
2/2
✓ Branch 0 taken 43148 times.
✓ Branch 1 taken 1672 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9802 {
9803
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.speed_mult,f))
9804 return 73;
9805
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.speed_div,f))
9806 return 74;
9807
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_iputzf(tmp_cmb.speed_add,f))
9808 return 75;
9809
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_appear,f))
9810 return 79;
9811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1672 times.
1672 if(!p_putc(tmp_cmb.sfx_disappear,f))
9812 return 80;
9813
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_loop,f))
9814 return 81;
9815
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_walking,f))
9816 return 82;
9817
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_standing,f))
9818 return 83;
9819
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.spr_appear,f))
9820 return 84;
9821
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.spr_disappear,f))
9822 return 85;
9823
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.spr_walking,f))
9824 return 86;
9825
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.spr_standing,f))
9826 return 87;
9827
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_tap,f))
9828 return 88;
9829
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_landing,f))
9830 return 89;
9831
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.spr_falling,f))
9832 return 90;
9833
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.spr_drowning,f))
9834 return 91;
9835
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9836 return 92;
9837
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_falling,f))
9838 return 93;
9839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1672 times.
1672 if(!p_putc(tmp_cmb.sfx_drowning,f))
9840 return 94;
9841
1/2
✓ Branch 0 taken 1672 times.
✗ Branch 1 not taken.
1672 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9842 return 95;
9843 1672 }
9844 44820 return 0;
9845 131132 }
9846
9847 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9848 {
9849 //these are here to bypass compiler warnings about unused arguments
9850 6 version=version;
9851 6 build=build;
9852
9853 word combos_used;
9854 6 dword section_id=ID_COMBOS;
9855 6 dword section_version=V_COMBOS;
9856 6 dword section_cversion=CV_COMBOS;
9857 // dword section_size=0;
9858 6 combos_used = count_combos()-start_combo;
9859
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
9860
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
9861 6 dword section_size = 0;
9862
9863 //section id
9864
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9865 {
9866 new_return(1);
9867 }
9868
9869 //section version info
9870
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9871 {
9872 new_return(2);
9873 }
9874
9875
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
9876 {
9877 new_return(3);
9878 }
9879
9880
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9881 {
9882 12 fake_pack_writing=(writecycle==0);
9883
9884 //section size
9885
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9886 {
9887 new_return(4);
9888 }
9889
9890 12 writesize=0;
9891
9892 //finally... section data
9893 12 combos_used=count_combos()-start_combo;
9894
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
9895
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
9896
9897
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
9898 {
9899 new_return(5);
9900 }
9901
9902 12 size_t end_combo = start_combo+combos_used;
9903
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
9904 {
9905 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9906
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
9907 97004 }
9908
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9909 {
9910 6 section_size=writesize;
9911 6 }
9912 12 }
9913
9914
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9915 {
9916 char ebuf[80];
9917 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9918 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9919 }
9920
9921 6 new_return(0);
9922 6 }
9923
9924 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9925 {
9926 //these are here to bypass compiler warnings about unused arguments
9927 6 version=version;
9928 6 build=build;
9929
9930 6 dword section_id=ID_COMBOALIASES;
9931 6 dword section_version=V_COMBOALIASES;
9932 6 dword section_cversion=CV_COMBOALIASES;
9933 6 dword section_size=0;
9934
9935 //section id
9936
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9937 {
9938 new_return(1);
9939 }
9940
9941 //section version info
9942
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9943 {
9944 new_return(2);
9945 }
9946
9947
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9948 {
9949 new_return(3);
9950 }
9951
9952
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9953 {
9954 12 fake_pack_writing=(writecycle==0);
9955
9956 //section size
9957
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9958 {
9959 new_return(4);
9960 }
9961
9962 12 writesize=0;
9963
9964 //finally... section data
9965
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9966 {
9967
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
9968 {
9969 new_return(5);
9970 }
9971
9972
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
9973 {
9974 new_return(6);
9975 }
9976
9977 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9978
9979
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
9980 {
9981 new_return(7);
9982 }
9983
9984
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
9985 {
9986 new_return(8);
9987 }
9988
9989
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
9990 {
9991 new_return(9);
9992 }
9993
9994
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
9995 {
9996
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
9997 {
9998 new_return(10);
9999 }
10000 99792 }
10001
10002
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10003 {
10004
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
10005 {
10006 new_return(11);
10007 }
10008 99792 }
10009 98304 }
10010
10011 //Combo pools!
10012 int16_t num_cpools;
10013
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10014 {
10015
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10016 {
10017 2 ++num_cpools;
10018 2 break;
10019 }
10020 98298 }
10021
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10022
10023
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10024 {
10025 new_return(12);
10026 }
10027
10028
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10029 {
10030 6 combo_pool const& pool = combo_pools[cp];
10031 6 int32_t num_combos = pool.combos.size();
10032
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10033 {
10034 new_return(13);
10035 }
10036
10037
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10038 {
10039 26 cpool_entry const& entry = pool.combos.at(q);
10040
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10041 {
10042 new_return(14);
10043 }
10044
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10045 {
10046 new_return(15);
10047 }
10048
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10049 {
10050 new_return(16);
10051 }
10052 26 }
10053 6 }
10054
10055 //Autocombos!
10056 int16_t num_cautos;
10057
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10058 {
10059
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10060 {
10061 ++num_cautos;
10062 break;
10063 }
10064 98304 }
10065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10066
10067
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10068 {
10069 new_return(17);
10070 }
10071
10072
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10073 {
10074 combo_auto const& cauto = combo_autos[ca];
10075 if (!p_putc(cauto.getType(), f))
10076 {
10077 new_return(18);
10078 }
10079 if (!p_iputl(cauto.getIconDisplay(), f))
10080 {
10081 new_return(19);
10082 }
10083 if (!p_iputl(cauto.getEraseCombo(), f))
10084 {
10085 new_return(20);
10086 }
10087 if (!p_putc(cauto.getFlags(), f))
10088 {
10089 new_return(21);
10090 }
10091 if (!p_putc(cauto.getArg(), f))
10092 {
10093 new_return(22);
10094 }
10095 int32_t num_combos = cauto.combos.size();
10096 if (!p_iputl(num_combos, f))
10097 {
10098 new_return(23);
10099 }
10100
10101 for (auto q = 0; q < num_combos; ++q)
10102 {
10103 autocombo_entry const& entry = cauto.combos.at(q);
10104 if (!p_putc(entry.ctype, f))
10105 {
10106 new_return(24);
10107 }
10108 if (!p_iputl(entry.cid, f))
10109 {
10110 new_return(25);
10111 }
10112 }
10113 }
10114
10115
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10116 {
10117 6 section_size=writesize;
10118 6 }
10119 12 }
10120
10121
10122
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10123 {
10124 char ebuf[80];
10125 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10126 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10127 }
10128
10129 6 new_return(0);
10130 }
10131
10132 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10133 {
10134 //these are here to bypass compiler warnings about unused arguments
10135 6 version=version;
10136 6 build=build;
10137 6 start_cset=start_cset;
10138 6 max_csets=max_csets;
10139
10140 6 dword section_id=ID_CSETS;
10141 6 dword section_version=V_CSETS;
10142 6 dword section_cversion=CV_CSETS;
10143 6 int32_t palcycles = count_palcycles(&QMisc);
10144 // int32_t palcyccount = count_palcycles(&QMisc);
10145 6 dword section_size = 0;
10146
10147 //section id
10148
10149
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10150 {
10151 new_return(1);
10152 }
10153
10154 //section version info
10155
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10156 {
10157 new_return(2);
10158 }
10159
10160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10161 {
10162 new_return(3);
10163 }
10164
10165
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10166 {
10167 12 fake_pack_writing=(writecycle==0);
10168
10169 //section size
10170
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10171 {
10172 new_return(4);
10173 }
10174
10175 12 writesize=0;
10176
10177 //finally... section data
10178
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10179 {
10180 new_return(5);
10181 }
10182
10183
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10184 {
10185 new_return(6);
10186 }
10187
10188
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10189 {
10190 new_return(15);
10191 }
10192
10193
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10194 {
10195
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10196 {
10197
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10198 {
10199 new_return(16);
10200 }
10201 828 }
10202
10203
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10204 {
10205
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10206 {
10207 new_return(17);
10208 }
10209 828 }
10210
10211
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10212 {
10213
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10214 {
10215 new_return(18);
10216 }
10217 828 }
10218 276 }
10219
10220
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10221 {
10222 6 section_size=writesize;
10223 6 }
10224 12 }
10225
10226
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10227 {
10228 char ebuf[80];
10229 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10230 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10231 }
10232
10233 6 new_return(0);
10234 }
10235
10236 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10237 {
10238 //these are here to bypass compiler warnings about unused arguments
10239 6 version=version;
10240 6 build=build;
10241 6 start_msgstr=start_msgstr;
10242 6 max_msgstrs=max_msgstrs;
10243
10244 6 dword section_id=ID_STRINGS;
10245 6 dword section_version=V_STRINGS;
10246 6 dword section_cversion=CV_STRINGS;
10247 6 dword section_size = 0;
10248
10249 //section id
10250
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10251 {
10252 new_return(1);
10253 }
10254
10255 //section version info
10256
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10257 {
10258 new_return(2);
10259 }
10260
10261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10262 {
10263 new_return(3);
10264 }
10265
10266
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10267 {
10268 12 fake_pack_writing=(writecycle==0);
10269
10270 //section size
10271
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10272 {
10273 new_return(4);
10274 }
10275
10276 12 writesize=0;
10277
10278 //finally... section data
10279
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10280 {
10281 return qe_invalid;
10282 }
10283
10284
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10285 {
10286 302 int32_t sz = MsgStrings[i].s.size();
10287
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10288
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10289 {
10290 return qe_invalid;
10291 }
10292
10293 302 char const* tmpstr = MsgStrings[i].s.c_str();
10294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10295 {
10296
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10297 {
10298 return qe_invalid;
10299 }
10300 302 }
10301
10302
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10303 {
10304 return qe_invalid;
10305 }
10306
10307
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10308 {
10309 return qe_invalid;
10310 }
10311
10312
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10313 {
10314 return qe_invalid;
10315 }
10316
10317
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10318 {
10319 return qe_invalid;
10320 }
10321
10322
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10323 {
10324 return qe_invalid;
10325 }
10326
10327
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10328 {
10329 return qe_invalid;
10330 }
10331
10332
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10333 {
10334 return qe_invalid;
10335 }
10336
10337
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10338 {
10339 return qe_invalid;
10340 }
10341
10342
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10343 {
10344 return qe_invalid;
10345 }
10346
10347
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10348 {
10349 return qe_invalid;
10350 }
10351
10352
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10353 {
10354 return qe_invalid;
10355 }
10356
10357
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10358 {
10359 return qe_invalid;
10360 }
10361
10362
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10363 {
10364
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10365 {
10366 return qe_invalid;
10367 }
10368 1208 }
10369
10370
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10371 {
10372 return qe_invalid;
10373 }
10374
10375
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10376 {
10377 return qe_invalid;
10378 }
10379
10380
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10381 {
10382 return qe_invalid;
10383 }
10384
10385
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10386 {
10387 return qe_invalid;
10388 }
10389
10390
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10391 {
10392 return qe_invalid;
10393 }
10394
10395
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10396 {
10397 return qe_invalid;
10398 }
10399
10400
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10401 {
10402 return qe_invalid;
10403 }
10404
10405
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10406 {
10407 return qe_invalid;
10408 }
10409
10410
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10411 {
10412 return qe_invalid;
10413 }
10414
10415
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10416 {
10417 return qe_invalid;
10418 }
10419
10420
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10421 {
10422 return qe_invalid;
10423 }
10424 302 }
10425
10426
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10427 {
10428 6 section_size=writesize;
10429 6 }
10430 12 }
10431
10432
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10433 {
10434 char ebuf[80];
10435 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10436 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10437 }
10438
10439 6 new_return(0);
10440 6 }
10441
10442 int32_t writestrings_text(PACKFILE *f)
10443 {
10444 std::map<int32_t, int32_t> msglistcache;
10445
10446 for(int32_t index = 1; index<msg_count; index++)
10447 {
10448 for(int32_t i=1; i<msg_count; i++)
10449 {
10450 if(MsgStrings[i].listpos==index)
10451 {
10452 msglistcache[index-1]=i;
10453 break;
10454 }
10455 }
10456 }
10457
10458 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10459 {
10460 fake_pack_writing=(writecycle==0);
10461 char ebuf[32];
10462
10463 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10464
10465 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10466 {
10467 return qe_invalid;
10468 }
10469
10470 for(int32_t i=1; i<msg_count; i++)
10471 {
10472 int32_t str = msglistcache[i-1];
10473
10474 if(!str)
10475 continue;
10476
10477 if(MsgStrings[str].nextstring != 0)
10478 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10479 else
10480 sprintf(ebuf,"\n\n___%d___\n", str);
10481
10482 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10483 {
10484 return qe_invalid;
10485 }
10486
10487 encode_msg_str(str);
10488
10489 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10490 {
10491 return qe_invalid;
10492 }
10493 }
10494 }
10495
10496 new_return(0);
10497 }
10498
10499 1 int32_t writestrings_tsv(PACKFILE *f)
10500 {
10501 1 std::stringstream ss;
10502
10503 int32_t str;
10504
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10505
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10506 35 encode_msg_str(str);
10507 35 return msgbuf;
10508 }},
10509
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10510
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10511
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10512
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10520
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10521
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10522
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10523
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10524
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10526
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10527
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10529
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10530
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10531
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10532
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10533 };
10534
10535
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10536 {
10537
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10538
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10539 1 break;
10540
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10541 }
10542
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10543
10544 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10545
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10546
10547
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10548 {
10549 35 str = i;
10550 35 auto& msg = MsgStrings[str];
10551
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10552 {
10553
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10554
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10555
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10556 35 break;
10557
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10558
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10559
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10560 35 }
10561
10562
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10563
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10564 {
10565 return qe_invalid;
10566 }
10567
10568 1 new_return(0);
10569 1 }
10570
10571 std::string parse_msg_str(std::string const& s);
10572
10573 void parse_strings_tsv(std::string tsv)
10574 {
10575 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10576 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10577 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10578 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10579 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10580 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10581 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10582 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10583 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10584 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10585 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10586 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10587 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10588 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10589 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10590 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10591 { "margin", [&](auto& msg, auto& text){
10592 std::vector<std::string> strs;
10593 util::split(text, strs, ' ');
10594 if (strs.size() != 4)
10595 throw std::runtime_error("margin field must have 4 components");
10596 msg.margins[0] = std::stoi(strs[0]);
10597 msg.margins[1] = std::stoi(strs[1]);
10598 msg.margins[2] = std::stoi(strs[2]);
10599 msg.margins[3] = std::stoi(strs[3]);
10600 } },
10601 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10602 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10603 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10604 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10605 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10606 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10607 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10608 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10609 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10610 };
10611
10612 std::vector<std::string> rows;
10613 util::split(tsv, rows, '\n');
10614 if (rows.size())
10615 {
10616 std::string last = rows.back();
10617 util::trimstr(last);
10618 if (last.empty())
10619 rows.pop_back();
10620 }
10621 if (rows.size() <= 1)
10622 throw std::runtime_error("missing header row");
10623
10624 std::vector<std::string> columns;
10625 util::split(rows[0], columns, '\t');
10626 for (auto name : columns)
10627 {
10628 if (!fields.contains(name))
10629 throw std::runtime_error(fmt::format("invalid field: {}", name));
10630 }
10631
10632 int start_index = 1;
10633 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10634 start_index += 1;
10635
10636 int num_strings = rows.size() - start_index + 1;
10637 if (num_strings > MAXMSGS-1)
10638 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10639
10640 std::vector<MsgStr> msgs;
10641 msgs.reserve(num_strings);
10642 for (int i = start_index; i < rows.size(); i++)
10643 {
10644 std::vector<std::string> strs;
10645 util::split(rows[i], strs, '\t');
10646 if (strs.size() != columns.size())
10647 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10648
10649 int j = 0;
10650 auto& msg = msgs.emplace_back();
10651 for (auto& name : columns)
10652 {
10653 auto& fn = fields[name];
10654 try
10655 {
10656 fn(msg, strs[j++]);
10657 }
10658 catch (std::exception& ex)
10659 {
10660 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10661 }
10662 }
10663 }
10664
10665 init_msgstrings(0, msgs.size());
10666 for (int i = 0; i < msgs.size(); i++)
10667 MsgStrings[i + 1] = msgs[i];
10668 msg_count = msgs.size();
10669 msglistcache.clear();
10670 }
10671
10672 bool isblanktile(tiledata *buf, int32_t i);
10673 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10674 {
10675 //these are here to bypass compiler warnings about unused arguments
10676 6 version=version;
10677 6 build=build;
10678
10679 int32_t tiles_used;
10680 6 dword section_id=ID_TILES;
10681 6 dword section_version=V_TILES;
10682 6 dword section_cversion=CV_TILES;
10683 6 al_trace("Counting tiles used\n");
10684 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10685
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10686
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10687 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10688 6 dword section_size = 0;
10689
10690 //section id
10691
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10692 {
10693 new_return(1);
10694 }
10695
10696 //section version info
10697
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10698 {
10699 new_return(2);
10700 }
10701
10702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10703 {
10704 new_return(3);
10705 }
10706
10707
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10708 {
10709 12 fake_pack_writing=(writecycle==0);
10710
10711 //section size
10712
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10713 {
10714 new_return(4);
10715 }
10716
10717 12 writesize=0;
10718
10719 //finally... section data
10720 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10721
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10722
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10723
10724
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10725 {
10726 new_return(5);
10727 }
10728
10729
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10730 {
10731
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10732 {
10733
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10734 new_return(8);
10735 238750 }
10736 else
10737 {
10738 209304 int format = newtilebuf[start_tile+i].format;
10739
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10740 {
10741 new_return(6);
10742 }
10743
10744
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10745 {
10746 byte temp_tile[128];
10747 207706 byte *di = temp_tile;
10748 207706 byte *src = newtilebuf[start_tile+i].data;
10749
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10750 {
10751 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10752 26586368 ++di;
10753 26586368 }
10754
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10755 {
10756 new_return(7);
10757 }
10758 207706 }
10759
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10760 {
10761 new_return(7);
10762 }
10763 }
10764 448054 }
10765
10766
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10767 {
10768 6 section_size=writesize;
10769 6 }
10770 12 }
10771
10772
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10773 {
10774 char ebuf[80];
10775 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10776 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10777 }
10778
10779 6 new_return(0);
10780 }
10781
10782 /* MIDI Format
10783 section_id LONG
10784 section_version WORD
10785 section_cversion WORD
10786 section_size LONG
10787 midi_flags 32 Byte ? BITFIELD[252]
10788
10789 [
10790 title 36
10791 start 4
10792 loop_start 4
10793 loop_end 4
10794 loop 2
10795 volume 2
10796 midi *
10797 ]
10798
10799 */
10800
10801 6 int32_t writemidis(PACKFILE *f)
10802 {
10803 6 dword section_id=ID_MIDIS;
10804 6 dword section_version=V_MIDIS;
10805 6 dword section_cversion=CV_MIDIS;
10806 6 dword section_size = 0;
10807
10808 //section id
10809
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10810 {
10811 new_return(1);
10812 }
10813
10814 //section version info
10815
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10816 {
10817 new_return(2);
10818 }
10819
10820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10821 {
10822 new_return(3);
10823 }
10824
10825
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10826 {
10827 12 fake_pack_writing=(writecycle==0);
10828
10829 //section size
10830
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10831 {
10832 new_return(4);
10833 }
10834
10835 12 writesize=0;
10836
10837 //finally... section data
10838
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10839 {
10840 new_return(5);
10841 }
10842
10843
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10844 {
10845
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10846 {
10847
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10848 {
10849 new_return(6);
10850 }
10851
10852
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
10853 {
10854 new_return(7);
10855 }
10856
10857
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
10858 {
10859 new_return(8);
10860 }
10861
10862
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
10863 {
10864 new_return(9);
10865 }
10866
10867
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
10868 {
10869 new_return(10);
10870 }
10871
10872
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
10873 {
10874 new_return(11);
10875 }
10876
10877
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10878 {
10879 new_return(12);
10880 }
10881
10882 60 byte format = MFORMAT_MIDI;
10883
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&format, sizeof(format),f))
10884 {
10885 new_return(13);
10886 }
10887
10888
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (!write_midi(customtunes[i].data, f)) new_return(14);
10889 60 }
10890 3024 }
10891
10892
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10893 {
10894 6 section_size=writesize;
10895 6 }
10896 12 }
10897
10898
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10899 {
10900 char ebuf[80];
10901 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10902 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10903 }
10904
10905 6 new_return(0);
10906 }
10907
10908 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10909 {
10910 6 dword section_id=ID_CHEATS;
10911 6 dword section_version=V_CHEATS;
10912 6 dword section_cversion=CV_CHEATS;
10913 6 dword section_size = 0;
10914
10915 //section id
10916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10917 {
10918 new_return(1);
10919 }
10920
10921 //section version info
10922
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10923 {
10924 new_return(2);
10925 }
10926
10927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10928 {
10929 new_return(3);
10930 }
10931
10932
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10933 {
10934 12 fake_pack_writing=(writecycle==0);
10935
10936 //section size
10937
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10938 {
10939 new_return(4);
10940 }
10941
10942 12 writesize=0;
10943
10944 //finally... section data
10945
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10946 {
10947 new_return(5);
10948 }
10949
10950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
10951 {
10952
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
10953 {
10954 new_return(6);
10955 }
10956
10957
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10958 {
10959 new_return(7);
10960 }
10961 12 }
10962
10963
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10964 {
10965 6 section_size=writesize;
10966 6 }
10967 12 }
10968
10969
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10970 {
10971 char ebuf[80];
10972 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10973 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10974 }
10975
10976 6 new_return(0);
10977 }
10978
10979 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10980 {
10981 //these are here to bypass compiler warnings about unused arguments
10982 6 Header=Header;
10983
10984 6 dword section_id=ID_GUYS;
10985 6 dword section_version=V_GUYS;
10986 6 dword section_cversion=CV_GUYS;
10987 6 dword section_size=0;
10988
10989 //section id
10990
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10991 {
10992 new_return(1);
10993 }
10994
10995 //section version info
10996
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10997 {
10998 new_return(2);
10999 }
11000
11001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11002 {
11003 new_return(3);
11004 }
11005
11006
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11007 {
11008 12 fake_pack_writing=(writecycle==0);
11009
11010 //section size
11011
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11012 {
11013 new_return(4);
11014 }
11015
11016 12 writesize=0;
11017
11018 //finally... section data
11019
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11020 {
11021
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11022 {
11023 new_return(5);
11024 }
11025 6144 }
11026
11027
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11028 {
11029 6144 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11030 6144 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11031
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags1, f))
11032 {
11033 new_return(6);
11034 }
11035
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags2, f))
11036 {
11037 new_return(7);
11038 }
11039
11040
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11041 {
11042 new_return(8);
11043 }
11044
11045
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11046 {
11047 new_return(9);
11048 }
11049
11050
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11051 {
11052 new_return(10);
11053 }
11054
11055
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11056 {
11057 new_return(11);
11058 }
11059
11060
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11061 {
11062 new_return(12);
11063 }
11064
11065
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11066 {
11067 new_return(13);
11068 }
11069
11070
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11071 {
11072 new_return(14);
11073 }
11074
11075
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11076 {
11077 new_return(15);
11078 }
11079
11080
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11081 {
11082 new_return(16);
11083 }
11084
11085
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11086 {
11087 new_return(17);
11088 }
11089
11090
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11091 {
11092 new_return(18);
11093 }
11094
11095
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11096 {
11097 new_return(19);
11098 }
11099
11100
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11101 {
11102 new_return(20);
11103 }
11104
11105
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11106 {
11107 new_return(21);
11108 }
11109
11110
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11111 {
11112 new_return(22);
11113 }
11114
11115
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11116 {
11117 new_return(23);
11118 }
11119
11120
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11121 {
11122 new_return(24);
11123 }
11124
11125
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11126 {
11127 new_return(25);
11128 }
11129
11130
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11131 {
11132 new_return(26);
11133 }
11134
11135
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11136 {
11137 new_return(27);
11138 }
11139
11140
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11141 {
11142 new_return(28);
11143 }
11144
11145
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11146 {
11147 new_return(29);
11148 }
11149
11150
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11151 {
11152 new_return(30);
11153 }
11154
11155
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11156 {
11157 new_return(31);
11158 }
11159
11160
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11161 {
11162 new_return(32);
11163 }
11164
11165
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[0], f))
11166 {
11167 new_return(33);
11168 }
11169
11170
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[1],f))
11171 {
11172 new_return(34);
11173 }
11174
11175
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[2],f))
11176 {
11177 new_return(35);
11178 }
11179
11180
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[3],f))
11181 {
11182 new_return(36);
11183 }
11184
11185
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[4],f))
11186 {
11187 new_return(37);
11188 }
11189
11190
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[5],f))
11191 {
11192 new_return(38);
11193 }
11194
11195
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[6],f))
11196 {
11197 new_return(39);
11198 }
11199
11200
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[7],f))
11201 {
11202 new_return(40);
11203 }
11204
11205
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[8],f))
11206 {
11207 new_return(41);
11208 }
11209
11210
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[9],f))
11211 {
11212 new_return(42);
11213 }
11214
11215
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11216 {
11217 new_return(43);
11218 }
11219
11220
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11221 {
11222 new_return(44);
11223 }
11224
11225
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11226 {
11227 new_return(45);
11228 }
11229
11230
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11231 {
11232
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11233 {
11234 new_return(46);
11235 }
11236 116736 }
11237
11238
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11239 {
11240 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11241 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11242 //Force SFX_HIT here.
11243
11244 }
11245
11246
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11247 {
11248 new_return(47);
11249 }
11250
11251
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11252 {
11253 new_return(48);
11254 }
11255
11256
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[10],f))
11257 {
11258 new_return(49);
11259 }
11260
11261
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[11],f))
11262 {
11263 new_return(50);
11264 }
11265
11266 //New 2.6 defences
11267
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11268 {
11269
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11270 {
11271 new_return(51);
11272 }
11273 135168 }
11274
11275 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11276
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11277 {
11278 new_return(52);
11279 }
11280
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11281 {
11282 new_return(53);
11283 }
11284
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11285 {
11286 new_return(54);
11287 }
11288
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11289 {
11290 new_return(55);
11291 }
11292
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11293 {
11294 new_return(56);
11295 }
11296 // These are not fixed types, but ints, so they are safe to use here.
11297
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11298 {
11299 new_return(57);
11300 }
11301
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11302 {
11303 new_return(58);
11304 }
11305
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11306 {
11307 new_return(59);
11308 }
11309
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11310 {
11311 new_return(60);
11312 }
11313
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11314 {
11315 new_return(61);
11316 }
11317
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11318 {
11319 new_return(62);
11320 }
11321
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11322 {
11323 new_return(63);
11324 }
11325
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11326 {
11327 new_return(64);
11328 }
11329
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11330 {
11331 new_return(65);
11332 }
11333
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11334 {
11335 new_return(66);
11336 }
11337
11338
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11339 {
11340
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11341 {
11342 new_return(67);
11343 }
11344 61440 }
11345
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11346 {
11347 new_return(68);
11348 }
11349 //misc 16->31
11350
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[15],f))
11351 {
11352 new_return(69);
11353 }
11354
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[16],f))
11355 {
11356 new_return(70);
11357 }
11358
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[17],f))
11359 {
11360 new_return(71);
11361 }
11362
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[18],f))
11363 {
11364 new_return(72);
11365 }
11366
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[19],f))
11367 {
11368 new_return(73);
11369 }
11370
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[20],f))
11371 {
11372 new_return(74);
11373 }
11374
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[21],f))
11375 {
11376 new_return(75);
11377 }
11378
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[22],f))
11379 {
11380 new_return(76);
11381 }
11382
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[23],f))
11383 {
11384 new_return(77);
11385 }
11386
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[24],f))
11387 {
11388 new_return(78);
11389 }
11390
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[25],f))
11391 {
11392 new_return(79);
11393 }
11394
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[26],f))
11395 {
11396 new_return(80);
11397 }
11398
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[27],f))
11399 {
11400 new_return(81);
11401 }
11402
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[28],f))
11403 {
11404 new_return(82);
11405 }
11406
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[29],f))
11407 {
11408 new_return(83);
11409 }
11410
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[30],f))
11411 {
11412 new_return(84);
11413 }
11414
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[31],f))
11415 {
11416 new_return(85);
11417 }
11418
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11419 {
11420
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11421 {
11422 new_return(86);
11423 }
11424 196608 }
11425
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11426 {
11427
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11428 {
11429 new_return(87);
11430 }
11431 196608 }
11432
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11433 {
11434 new_return(88);
11435 }
11436
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11437 {
11438
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11439 {
11440 new_return(89);
11441 }
11442 49152 }
11443
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11444 {
11445
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(0,f))
11446 {
11447 new_return(90);
11448 }
11449 12288 }
11450
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11451 {
11452 new_return(91);
11453 }
11454 //somehow forgot these in the older builds -Z
11455
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[12],f))
11456 {
11457 new_return(92);
11458 }
11459
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[13],f))
11460 {
11461 new_return(93);
11462 }
11463
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[14],f))
11464 {
11465 new_return(94);
11466 }
11467
11468 //Enemy Editor InitD[] labels
11469
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11470 {
11471
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11472 {
11473
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11474 {
11475 new_return(95);
11476 }
11477 3194880 }
11478
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11479 {
11480
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11481 {
11482 new_return(96);
11483 }
11484 3194880 }
11485 49152 }
11486
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11487 {
11488 new_return(97);
11489 }
11490 //eweapon initD
11491
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11492 {
11493
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11494 {
11495 new_return(98);
11496 }
11497 49152 }
11498
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11499 new_return(99);
11500
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11501 new_return(100);
11502
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11503 new_return(101);
11504
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11505 new_return(102);
11506
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_putc(guysbuf[i].wunblockable, f))
11507 new_return(103);
11508
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].wmoveflags, f))
11509 new_return(104);
11510
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weapoverrideFLAGS, f))
11511 new_return(105);
11512
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_tilew, f))
11513 new_return(106);
11514
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_tileh, f))
11515 new_return(107);
11516
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hxsz, f))
11517 new_return(108);
11518
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hysz, f))
11519 new_return(109);
11520
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hzsz, f))
11521 new_return(110);
11522
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hxofs, f))
11523 new_return(111);
11524
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hyofs, f))
11525 new_return(112);
11526
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_xofs, f))
11527 new_return(113);
11528
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_yofs, f))
11529 new_return(114);
11530
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].wstep, f))
11531 new_return(115);
11532
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 6144 times.
36864 for(int32_t q = 0; q < WPNSPR_MAX; ++q)
11533 {
11534
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if (!p_iputw(guysbuf[i].burnsprs[q], f))
11535 new_return(116);
11536
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if (!p_iputw(guysbuf[i].light_rads[q], f))
11537 new_return(117);
11538 30720 }
11539
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_putc(guysbuf[i].specialsfx, f))
11540 new_return(118);
11541 6144 }
11542
11543
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11544 {
11545 6 section_size=writesize;
11546 6 }
11547 12 }
11548
11549
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11550 {
11551 char ebuf[80];
11552 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11553 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11554 }
11555
11556 6 new_return(0);
11557 }
11558
11559 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11560 {
11561 //these are here to bypass compiler warnings about unused arguments
11562 6 Header=Header;
11563
11564 6 dword section_id=ID_HEROSPRITES;
11565 6 dword section_version=V_HEROSPRITES;
11566 6 dword section_cversion=CV_HEROSPRITES;
11567 6 dword section_size=0;
11568
11569 //section id
11570
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11571 {
11572 new_return(1);
11573 }
11574
11575 //section version info
11576
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11577 {
11578 new_return(2);
11579 }
11580
11581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11582 {
11583 new_return(3);
11584 }
11585
11586
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11587 {
11588 12 fake_pack_writing=(writecycle==0);
11589
11590 //section size
11591
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11592 {
11593 new_return(4);
11594 }
11595
11596 12 writesize=0;
11597
11598 //finally... section data
11599
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11600 {
11601
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11602 {
11603 new_return(5);
11604 }
11605
11606
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11607 {
11608 new_return(5);
11609 }
11610
11611
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11612 {
11613 new_return(5);
11614 }
11615 48 }
11616
11617
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11618 {
11619
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11620 {
11621 new_return(6);
11622 }
11623
11624
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11625 {
11626 new_return(6);
11627 }
11628
11629
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11630 {
11631 new_return(6);
11632 }
11633 48 }
11634
11635
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11636 {
11637
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11638 {
11639 new_return(7);
11640 }
11641
11642
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11643 {
11644 new_return(7);
11645 }
11646
11647
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11648 {
11649 new_return(7);
11650 }
11651 48 }
11652
11653
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11654 {
11655
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11656 {
11657 new_return(8);
11658 }
11659
11660
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11661 {
11662 new_return(8);
11663 }
11664
11665
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11666 {
11667 new_return(8);
11668 }
11669 48 }
11670
11671
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11672 {
11673
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11674 {
11675 new_return(8);
11676 }
11677
11678
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11679 {
11680 new_return(8);
11681 }
11682
11683
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11684 {
11685 new_return(8);
11686 }
11687 48 }
11688
11689
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11690 {
11691
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11692 {
11693 new_return(9);
11694 }
11695
11696
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11697 {
11698 new_return(9);
11699 }
11700
11701
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11702 {
11703 new_return(9);
11704 }
11705 48 }
11706
11707
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11708 {
11709
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11710 {
11711 new_return(10);
11712 }
11713
11714
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11715 {
11716 new_return(10);
11717 }
11718
11719
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11720 {
11721 new_return(10);
11722 }
11723 48 }
11724
11725
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11726 {
11727 new_return(11);
11728 }
11729
11730
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11731 {
11732 new_return(11);
11733 }
11734
11735
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11736 {
11737 new_return(11);
11738 }
11739
11740
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11741 {
11742
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11743 {
11744
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11745 {
11746 new_return(12);
11747 }
11748
11749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11750 {
11751 new_return(12);
11752 }
11753
11754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11755 {
11756 new_return(12);
11757 }
11758 72 }
11759 24 }
11760
11761
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11762 {
11763
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11764 {
11765 new_return(13);
11766 }
11767
11768
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11769 {
11770 new_return(13);
11771 }
11772
11773
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11774 {
11775 new_return(13);
11776 }
11777 48 }
11778
11779
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11780 {
11781
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11782 {
11783 new_return(13);
11784 }
11785
11786
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11787 {
11788 new_return(13);
11789 }
11790
11791
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11792 {
11793 new_return(13);
11794 }
11795 48 }
11796
11797
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11798 {
11799 new_return(14);
11800 }
11801
11802 //{ V_HEROSPRITES >= 7
11803
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11804 {
11805
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11806 new_return(15);
11807
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11808 new_return(15);
11809
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11810 new_return(15);
11811 48 }
11812
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11813 {
11814
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11815 new_return(15);
11816
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11817 new_return(15);
11818
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11819 new_return(15);
11820 48 }
11821
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11822 {
11823
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11824 new_return(15);
11825
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11826 new_return(15);
11827
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11828 new_return(15);
11829 48 }
11830
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11831 {
11832
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11833 new_return(15);
11834
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11835 new_return(15);
11836
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11837 new_return(15);
11838 48 }
11839
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11840 {
11841
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11842 new_return(15);
11843
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11844 new_return(15);
11845
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11846 new_return(15);
11847 48 }
11848
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11849 {
11850
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11851 new_return(15);
11852
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11853 new_return(15);
11854
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11855 new_return(15);
11856 48 }
11857
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11858 {
11859
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11860 new_return(15);
11861
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11862 new_return(15);
11863
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11864 new_return(15);
11865 48 }
11866
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11867 {
11868
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11869 new_return(15);
11870
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11871 new_return(15);
11872
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11873 new_return(15);
11874 48 }
11875
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11876 {
11877
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
11878 new_return(15);
11879
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11880 new_return(15);
11881
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11882 new_return(15);
11883
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11884 new_return(15);
11885 48 }
11886
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11887 {
11888
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11889 new_return(15);
11890
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11891 new_return(15);
11892
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11893 new_return(15);
11894 48 }
11895
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11896 {
11897
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
11898 new_return(15);
11899
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11900 new_return(15);
11901
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11902 new_return(15);
11903 48 }
11904
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11905 {
11906
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11907 new_return(15);
11908
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11909 new_return(15);
11910
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11911 new_return(15);
11912 48 }
11913
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11914 {
11915
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
11916 new_return(15);
11917
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11918 new_return(15);
11919
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11920 new_return(15);
11921 48 }
11922
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11923 {
11924
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11925 new_return(15);
11926
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11927 new_return(15);
11928
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11929 new_return(15);
11930 48 }
11931
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11932 {
11933
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
11934 new_return(15);
11935
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11936 new_return(15);
11937
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11938 new_return(15);
11939 48 }
11940
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11941 {
11942
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
11943 new_return(15);
11944
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11945 new_return(15);
11946
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11947 new_return(15);
11948 48 }
11949
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11950 {
11951
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11952 new_return(15);
11953
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11954 new_return(15);
11955
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11956 new_return(15);
11957 48 }
11958
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11959 {
11960
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
11961 new_return(15);
11962
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11963 new_return(15);
11964
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11965 new_return(15);
11966 48 }
11967
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11968 {
11969
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
11970 new_return(15);
11971
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
11972 new_return(15);
11973
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
11974 new_return(15);
11975 48 }
11976
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11977 {
11978
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
11979 new_return(15);
11980
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11981 new_return(15);
11982
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11983 new_return(15);
11984 48 }
11985
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11986 {
11987
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11988 new_return(15);
11989
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11990 new_return(15);
11991
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11992 new_return(15);
11993 48 }
11994
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11995 {
11996
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
11997 new_return(15);
11998
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
11999 new_return(15);
12000
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
12001 new_return(15);
12002 48 }
12003
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12004 {
12005
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
12006 new_return(15);
12007
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12008 new_return(15);
12009
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12010 new_return(15);
12011 48 }
12012
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12013 {
12014
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12015 new_return(15);
12016
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12017 new_return(15);
12018
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12019 new_return(15);
12020 36 }
12021
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12022 {
12023
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12024 new_return(16);
12025
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12026 new_return(16);
12027
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12028 new_return(16);
12029 48 }
12030
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12031 {
12032
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12033 new_return(17);
12034
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12035 new_return(17);
12036
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12037 new_return(17);
12038 48 }
12039
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12040 {
12041
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12042 new_return(17);
12043
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12044 new_return(17);
12045
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12046 new_return(17);
12047 48 }
12048
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12049 {
12050
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12051 new_return(17);
12052
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12053 new_return(17);
12054
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12055 new_return(17);
12056 48 }
12057
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12058 {
12059
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12060 new_return(18);
12061
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12062 new_return(18);
12063
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12064 new_return(18);
12065 48 }
12066
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12067 {
12068
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12069 new_return(19);
12070 48 }
12071
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12072 {
12073
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12074 new_return(20);
12075
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12076 new_return(20);
12077
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12078 new_return(20);
12079 36 }
12080
12081
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12082 {
12083 new_return(21);
12084 }
12085
12086
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12087 {
12088 new_return(21);
12089 }
12090
12091
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12092 {
12093 new_return(21);
12094 }
12095
12096
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12097 {
12098
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12099 new_return(22);
12100
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12101 new_return(22);
12102
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12103 new_return(22);
12104 48 }
12105
12106
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12107 {
12108
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12109 {
12110 new_return(23);
12111 }
12112
12113
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12114 {
12115 new_return(23);
12116 }
12117
12118
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12119 {
12120 new_return(23);
12121 }
12122 48 }
12123
12124
12125
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12126 {
12127
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12128 new_return(15);
12129 1752 }
12130 //}
12131
12132
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12133 {
12134 6 section_size=writesize;
12135 6 }
12136 12 }
12137
12138 //More data will come here
12139
12140
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12141 {
12142 char ebuf[80];
12143 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12144 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12145 }
12146
12147 6 new_return(0);
12148 }
12149
12150 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12151 {
12152 6 dword section_id=ID_SUBSCREEN;
12153 6 dword section_version=V_SUBSCREEN;
12154 6 dword section_cversion=CV_SUBSCREEN;
12155 6 dword section_size=0;
12156
12157 //section id
12158
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12159 {
12160 new_return(1);
12161 }
12162
12163 //section version info
12164
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12165 {
12166 new_return(2);
12167 }
12168
12169
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12170 {
12171 new_return(3);
12172 }
12173
12174
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12175 {
12176 12 fake_pack_writing=(writecycle==0);
12177
12178 //section size
12179
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12180 {
12181 new_return(4);
12182 }
12183
12184 12 writesize=0;
12185
12186 12 byte sz = subscreens_active.size();
12187
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12188 new_return(5);
12189
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12190 {
12191 66 int32_t ret = subscreens_active[i].write(f);
12192 66 fake_pack_writing=(writecycle==0);
12193
12194
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12195 new_return(ret);
12196 66 }
12197
12198 12 sz = subscreens_passive.size();
12199
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12200 new_return(5);
12201
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12202 {
12203 50 int32_t ret = subscreens_passive[i].write(f);
12204 50 fake_pack_writing=(writecycle==0);
12205
12206
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12207 new_return(ret);
12208 50 }
12209
12210 12 sz = subscreens_overlay.size();
12211
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12212 new_return(5);
12213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12214 {
12215 int32_t ret = subscreens_overlay[i].write(f);
12216 fake_pack_writing=(writecycle==0);
12217
12218 if(ret!=0)
12219 new_return(ret);
12220 }
12221
12222
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12223 {
12224 6 section_size=writesize;
12225 6 }
12226 12 }
12227
12228
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12229 {
12230 char ebuf[80];
12231 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12232 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12233 }
12234
12235 6 new_return(0);
12236 6 }
12237
12238 extern script_data *ffscripts[NUMSCRIPTFFC];
12239 extern script_data *itemscripts[NUMSCRIPTITEM];
12240 extern script_data *guyscripts[NUMSCRIPTGUYS];
12241 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12242 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12243 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12244 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12245 extern script_data *playerscripts[NUMSCRIPTHERO];
12246 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12247 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12248 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12249 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12250 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12251
12252 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12253 {
12254 6 dword section_id = ID_FFSCRIPT;
12255 6 dword section_version = V_FFSCRIPT;
12256 6 dword section_cversion = CV_FFSCRIPT;
12257 6 dword section_size = 0;
12258 6 dword zasmmeta_version = METADATA_V;
12259 6 byte numscripts = 0;
12260 6 numscripts = numscripts; //to avoid unused variables warnings
12261
12262 //section id
12263
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12264 {
12265 new_return(1);
12266 }
12267
12268 //section version info
12269
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12270 {
12271 new_return(2);
12272 }
12273
12274
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12275 {
12276 new_return(3);
12277 }
12278
12279
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12280 {
12281 new_return(4);
12282 }
12283
12284
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12285 {
12286 12 fake_pack_writing=(writecycle==0);
12287
12288 //section size
12289
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12290 {
12291 new_return(5);
12292 }
12293
12294 12 writesize=0;
12295
12296
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12297 {
12298 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12299 6144 fake_pack_writing=(writecycle==0);
12300
12301
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12302 {
12303 new_return(ret);
12304 }
12305 6144 }
12306
12307
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12308 {
12309 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12310 3072 fake_pack_writing=(writecycle==0);
12311
12312
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12313 {
12314 new_return(ret);
12315 }
12316 3072 }
12317
12318
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12319 {
12320 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12321 3072 fake_pack_writing=(writecycle==0);
12322
12323
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12324 {
12325 new_return(ret);
12326 }
12327 3072 }
12328
12329
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12330
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12331 {
12332 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12333 3072 fake_pack_writing=(writecycle==0);
12334
12335
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12336 {
12337 new_return(ret);
12338 }
12339 3072 }
12340
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12341
12342
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12343 {
12344 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12345 3072 fake_pack_writing=(writecycle==0);
12346
12347
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12348 {
12349 new_return(ret);
12350 }
12351 3072 }
12352
12353
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12354 {
12355 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12356 96 fake_pack_writing=(writecycle==0);
12357
12358
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12359 {
12360 new_return(ret);
12361 }
12362 96 }
12363
12364
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12365 {
12366 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12367 60 fake_pack_writing=(writecycle==0);
12368
12369
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12370 {
12371 new_return(ret);
12372 }
12373 60 }
12374
12375
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12376 {
12377 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12378 3072 fake_pack_writing=(writecycle==0);
12379
12380
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12381 {
12382 new_return(ret);
12383 }
12384 3072 }
12385
12386
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12387 {
12388 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12389 3072 fake_pack_writing=(writecycle==0);
12390
12391
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12392 {
12393 new_return(ret);
12394 }
12395 3072 }
12396
12397
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12398 {
12399 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12400 3072 fake_pack_writing=(writecycle==0);
12401
12402
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12403 {
12404 new_return(ret);
12405 }
12406 3072 }
12407
12408
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12409 {
12410 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12411 3072 fake_pack_writing=(writecycle==0);
12412
12413
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12414 {
12415 new_return(ret);
12416 }
12417 3072 }
12418
12419
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12420 {
12421 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12422 6144 fake_pack_writing=(writecycle==0);
12423
12424
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12425 {
12426 new_return(ret);
12427 }
12428 6144 }
12429
12430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12431 {
12432 new_return(2000);
12433 }
12434
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12435 {
12436 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12437 6144 fake_pack_writing=(writecycle==0);
12438
12439
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12440 {
12441 new_return(ret);
12442 }
12443 6144 }
12444
12445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12446 {
12447 new_return(2001);
12448 }
12449
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12450 {
12451 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12452 3072 fake_pack_writing=(writecycle==0);
12453
12454
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12455 {
12456 new_return(ret);
12457 }
12458 3072 }
12459
12460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12461 {
12462 new_return(2001);
12463 }
12464
12465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12466 {
12467 new_return(2002);
12468 }
12469
12470 12 word numffcbindings=0;
12471
12472
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12473 {
12474
2/2
✓ Branch 0 taken 5934 times.
✓ Branch 1 taken 198 times.
6132 if(it->second.scriptname != "")
12475 {
12476 198 numffcbindings++;
12477 198 }
12478 6132 }
12479
12480
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12481 {
12482 new_return(2003);
12483 }
12484
12485
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12486 {
12487
2/2
✓ Branch 0 taken 5934 times.
✓ Branch 1 taken 198 times.
6132 if(it->second.scriptname != "")
12488 {
12489
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
198 if(!p_iputw(it->first,f))
12490 {
12491 new_return(2004);
12492 }
12493
12494
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
198 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12495 {
12496 new_return(2005);
12497 }
12498
12499
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
198 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12500 {
12501 new_return(2006);
12502 }
12503 198 }
12504 6132 }
12505
12506 12 word numglobalbindings=0;
12507
12508
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12509 {
12510
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12511 {
12512 24 numglobalbindings++;
12513 24 }
12514 96 }
12515
12516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12517 {
12518 new_return(2007);
12519 }
12520
12521
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12522 {
12523
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12524 {
12525
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12526 {
12527 new_return(2008);
12528 }
12529
12530
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12531 {
12532 new_return(2009);
12533 }
12534
12535
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12536 {
12537 new_return(2010);
12538 }
12539 24 }
12540 96 }
12541
12542 12 word numitembindings=0;
12543
12544
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12545 {
12546
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12547 {
12548 26 numitembindings++;
12549 26 }
12550 3060 }
12551
12552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12553 {
12554 new_return(2011);
12555 }
12556
12557
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12558 {
12559
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12560 {
12561
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12562 {
12563 new_return(2012);
12564 }
12565
12566
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12567 {
12568 new_return(2013);
12569 }
12570
12571
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12572 {
12573 new_return(2014);
12574 }
12575 26 }
12576 3060 }
12577
12578 //new script types
12579 //npc scripts
12580 12 word numnpcbindings=0;
12581
12582
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12583 {
12584
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12585 {
12586 numnpcbindings++;
12587 }
12588 3060 }
12589
12590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12591 {
12592 new_return(2015);
12593 }
12594
12595
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12596 {
12597
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12598 {
12599 if(!p_iputw(it->first,f))
12600 {
12601 new_return(2016);
12602 }
12603
12604 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12605 {
12606 new_return(2017);
12607 }
12608
12609 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12610 {
12611 new_return(2018);
12612 }
12613 }
12614 3060 }
12615
12616 //lweapon
12617
12618 12 word numlwpnbindings=0;
12619
12620
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12621 {
12622
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12623 {
12624 numlwpnbindings++;
12625 }
12626 3060 }
12627
12628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12629 {
12630 new_return(2019);
12631 }
12632
12633
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12634 {
12635
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12636 {
12637 if(!p_iputw(it->first,f))
12638 {
12639 new_return(2020);
12640 }
12641
12642 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12643 {
12644 new_return(2021);
12645 }
12646
12647 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12648 {
12649 new_return(2022);
12650 }
12651 }
12652 3060 }
12653
12654 //////
12655
12656 //eweapon
12657
12658
12659 12 word numewpnbindings=0;
12660
12661
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12662 {
12663
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12664 {
12665 numewpnbindings++;
12666 }
12667 3060 }
12668
12669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12670 {
12671 new_return(2023);
12672 }
12673
12674
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12675 {
12676
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12677 {
12678 if(!p_iputw(it->first,f))
12679 {
12680 new_return(2024);
12681 }
12682
12683 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12684 {
12685 new_return(2025);
12686 }
12687
12688 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12689 {
12690 new_return(2026);
12691 }
12692 }
12693 3060 }
12694
12695 //player scripts
12696 12 word numherobindings=0;
12697
12698
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12699 {
12700
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12701 {
12702 2 numherobindings++;
12703 2 }
12704 48 }
12705
12706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12707 {
12708 new_return(2027);
12709 }
12710
12711
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12712 {
12713
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12714 {
12715
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12716 {
12717 new_return(2028);
12718 }
12719
12720
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12721 {
12722 new_return(2029);
12723 }
12724
12725
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12726 {
12727 new_return(2030);
12728 }
12729 2 }
12730 48 }
12731
12732 //dmap scripts
12733 12 word numdmapbindings=0;
12734
12735
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12736 {
12737
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12738 {
12739 4 numdmapbindings++;
12740 4 }
12741 3060 }
12742
12743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12744 {
12745 new_return(2031);
12746 }
12747
12748
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12749 {
12750
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12751 {
12752
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12753 {
12754 new_return(2032);
12755 }
12756
12757
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12758 {
12759 new_return(2033);
12760 }
12761
12762
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12763 {
12764 new_return(2034);
12765 }
12766 4 }
12767 3060 }
12768
12769 //screen scripts
12770 12 word numscreenbindings=0;
12771
12772
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12773 {
12774
2/2
✓ Branch 0 taken 3042 times.
✓ Branch 1 taken 18 times.
3060 if(it->second.scriptname != "")
12775 {
12776 18 numscreenbindings++;
12777 18 }
12778 3060 }
12779
12780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12781 {
12782 new_return(2035);
12783 }
12784
12785
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12786 {
12787
2/2
✓ Branch 0 taken 3042 times.
✓ Branch 1 taken 18 times.
3060 if(it->second.scriptname != "")
12788 {
12789
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
12790 {
12791 new_return(2036);
12792 }
12793
12794
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12795 {
12796 new_return(2037);
12797 }
12798
12799
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12800 {
12801 new_return(2038);
12802 }
12803 18 }
12804 3060 }
12805 //item sprite scripts
12806 12 word numitemspritebindings=0;
12807
12808
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12809 {
12810
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12811 {
12812 numitemspritebindings++;
12813 }
12814 3060 }
12815
12816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12817 {
12818 new_return(2039);
12819 }
12820
12821
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12822 {
12823
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12824 {
12825 if(!p_iputw(it->first,f))
12826 {
12827 new_return(2040);
12828 }
12829
12830 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12831 {
12832 new_return(2041);
12833 }
12834
12835 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12836 {
12837 new_return(2042);
12838 }
12839 }
12840 3060 }
12841
12842 //combo scripts
12843 12 word numcombobindings=0;
12844
12845
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12846 {
12847
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12848 {
12849 numcombobindings++;
12850 }
12851 6132 }
12852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12853 {
12854 new_return(2043);
12855 }
12856
12857
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12858 {
12859
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12860 {
12861 if(!p_iputw(it->first,f))
12862 {
12863 new_return(2044);
12864 }
12865
12866 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12867 {
12868 new_return(2045);
12869 }
12870
12871 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12872 {
12873 new_return(2046);
12874 }
12875 }
12876 6132 }
12877 //subscreen scripts
12878 12 word numgenericbindings=0;
12879
12880
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12881 {
12882
2/2
✓ Branch 0 taken 6122 times.
✓ Branch 1 taken 10 times.
6132 if(it->second.scriptname != "")
12883 {
12884 10 numgenericbindings++;
12885 10 }
12886 6132 }
12887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12888 {
12889 new_return(2043);
12890 }
12891
12892
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12893 {
12894
2/2
✓ Branch 0 taken 6122 times.
✓ Branch 1 taken 10 times.
6132 if(it->second.scriptname != "")
12895 {
12896
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12897 {
12898 new_return(2044);
12899 }
12900
12901
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12902 {
12903 new_return(2045);
12904 }
12905
12906
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12907 {
12908 new_return(2046);
12909 }
12910 10 }
12911 6132 }
12912
12913 //generic scripts
12914 12 word numsubscreenbindings=0;
12915
12916
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12917 {
12918
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12919 {
12920 numsubscreenbindings++;
12921 }
12922 3060 }
12923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12924 {
12925 new_return(2047);
12926 }
12927
12928
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12929 {
12930
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12931 {
12932 if(!p_iputw(it->first,f))
12933 {
12934 new_return(2048);
12935 }
12936
12937 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12938 {
12939 new_return(2049);
12940 }
12941
12942 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12943 {
12944 new_return(2050);
12945 }
12946 }
12947 3060 }
12948
12949
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12950 {
12951 6 section_size=writesize;
12952 6 }
12953 12 }
12954
12955
12956
12957
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12958 {
12959 char ebuf[80];
12960 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12961 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12962 }
12963
12964 6 new_return(0);
12965 //return 0; //this is just here to stomp the compiler from whining.
12966 //the irony is that it causes an "unreachable code" warning.
12967 6 }
12968
12969 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
12970 {
12971 //these are here to bypass compiler warnings about unused arguments
12972 46236 Header=Header;
12973 46236 i=i;
12974
12975
2/2
✓ Branch 0 taken 9506 times.
✓ Branch 1 taken 36730 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
12976
12977
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
12978 {
12979 new_return(6);
12980 }
12981
12982 //Metadata
12983 46236 zasm_meta const& tmeta = (*script)->meta;
12984
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
12985 {
12986 new_return(7);
12987 }
12988
12989
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
12990 {
12991 new_return(8);
12992 }
12993
12994
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
12995 {
12996 new_return(9);
12997 }
12998
12999
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
13000 {
13001 new_return(10);
13002 }
13003
13004
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13005 {
13006
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
13007 new_return(11);
13008 369888 }
13009
13010
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13011 {
13012
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
13013 {
13014 new_return(12);
13015 }
13016 369888 }
13017
13018
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13019 {
13020 new_return(13);
13021 }
13022
13023
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13024 {
13025 new_return(14);
13026 }
13027
13028
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13029 {
13030 new_return(15);
13031 }
13032
13033
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13034 {
13035 new_return(16);
13036 }
13037
13038
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13039 {
13040 new_return(17);
13041 }
13042
13043
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13044 new_return(18);
13045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13046 new_return(19);
13047
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13048 {
13049
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13050 new_return(27);
13051
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13052 new_return(28);
13053 462360 }
13054
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13055 {
13056
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13057 new_return(29);
13058
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13059 new_return(30);
13060 369888 }
13061
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13062 {
13063
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13064 new_return(31);
13065
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13066 new_return(32);
13067 369888 }
13068
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13069 {
13070
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13071 new_return(33);
13072
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13073 new_return(34);
13074 739776 }
13075
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13076 {
13077
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13078 new_return(35);
13079
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13080 new_return(36);
13081 369888 }
13082
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13083 {
13084
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13085 new_return(37);
13086 369888 }
13087
13088
2/2
✓ Branch 0 taken 36730 times.
✓ Branch 1 taken 632640 times.
669370 for(int32_t j=0; j<num_commands; j++)
13089 {
13090 632640 auto& zas = (*script)->zasm_script->zasm[j];
13091
1/2
✓ Branch 0 taken 632640 times.
✗ Branch 1 not taken.
632640 if(!p_iputw(zas.command,f))
13092 {
13093 new_return(20);
13094 }
13095
13096
2/2
✓ Branch 0 taken 623134 times.
✓ Branch 1 taken 9506 times.
632640 if(zas.command==0xFFFF)
13097 {
13098 9506 break;
13099 }
13100 else
13101 {
13102
1/2
✓ Branch 0 taken 623134 times.
✗ Branch 1 not taken.
623134 if(!p_iputl(zas.arg1,f))
13103 {
13104 new_return(21);
13105 }
13106
13107
1/2
✓ Branch 0 taken 623134 times.
✗ Branch 1 not taken.
623134 if(!p_iputl(zas.arg2,f))
13108 {
13109 new_return(22);
13110 }
13111
13112
1/2
✓ Branch 0 taken 623134 times.
✗ Branch 1 not taken.
623134 if(!p_iputl(zas.arg3,f))
13113 {
13114 new_return(23);
13115 }
13116
13117 623134 uint32_t sz = 0;
13118
2/2
✓ Branch 0 taken 2940 times.
✓ Branch 1 taken 620194 times.
623134 if(zas.strptr)
13119 2940 sz = zas.strptr->size();
13120
1/2
✓ Branch 0 taken 623134 times.
✗ Branch 1 not taken.
623134 if(!p_iputl(sz,f))
13121 {
13122 new_return(23);
13123 }
13124
2/2
✓ Branch 0 taken 620200 times.
✓ Branch 1 taken 2934 times.
623134 if(sz)
13125 {
13126 2934 auto& str = *zas.strptr;
13127
2/2
✓ Branch 0 taken 225950 times.
✓ Branch 1 taken 2934 times.
228884 for(size_t q = 0; q < sz; ++q)
13128 {
13129
1/2
✓ Branch 0 taken 225950 times.
✗ Branch 1 not taken.
225950 if(!p_putc(str[q],f))
13130 {
13131 new_return(24);
13132 }
13133 225950 }
13134 2934 }
13135 623134 sz = 0;
13136
2/2
✓ Branch 0 taken 623008 times.
✓ Branch 1 taken 126 times.
623134 if(zas.vecptr)
13137 126 sz = zas.vecptr->size();
13138
1/2
✓ Branch 0 taken 623134 times.
✗ Branch 1 not taken.
623134 if(!p_iputl(sz,f))
13139 {
13140 new_return(25);
13141 }
13142
2/2
✓ Branch 0 taken 623008 times.
✓ Branch 1 taken 126 times.
623134 if(sz) //vector found
13143 {
13144 126 auto& vec = *zas.vecptr;
13145
2/2
✓ Branch 0 taken 882 times.
✓ Branch 1 taken 126 times.
1008 for(size_t q = 0; q < sz; ++q)
13146 {
13147
1/2
✓ Branch 0 taken 882 times.
✗ Branch 1 not taken.
882 if(!p_iputl(vec[q],f))
13148 {
13149 new_return(26);
13150 }
13151 882 }
13152 126 }
13153 }
13154 623134 }
13155
13156 46236 new_return(0);
13157 }
13158
13159 extern SAMPLE customsfxdata[WAV_COUNT];
13160 extern uint8_t customsfxflag[WAV_COUNT>>3];
13161
13162 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13163 {
13164 //these are here to bypass compiler warnings about unused arguments
13165 6 Header=Header;
13166
13167 6 dword section_id=ID_SFX;
13168 6 dword section_version=V_SFX;
13169 6 dword section_cversion=CV_SFX;
13170 6 dword section_size=0;
13171
13172 //section id
13173
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13174 {
13175 new_return(1);
13176 }
13177
13178 //section version info
13179
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13180 {
13181 new_return(2);
13182 }
13183
13184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13185 {
13186 new_return(3);
13187 }
13188
13189
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13190 {
13191 12 fake_pack_writing=(writecycle==0);
13192
13193 //section size
13194
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13195 {
13196 new_return(4);
13197 }
13198
13199 12 writesize=0;
13200
13201
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13202 {
13203
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13204 {
13205 new_return(5);
13206 }
13207 384 }
13208
13209
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13210 {
13211
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13212 2240 continue;
13213
13214
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13215 {
13216 new_return(5);
13217 }
13218 820 }
13219
13220
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13221 {
13222
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13223 2240 continue;
13224
13225
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13226 {
13227 new_return(5);
13228 }
13229
13230
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13231 {
13232 new_return(6);
13233 }
13234
13235
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13236 {
13237 new_return(7);
13238 }
13239
13240
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13241 {
13242 new_return(8);
13243 }
13244
13245
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13246 {
13247 new_return(9);
13248 }
13249
13250
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13251 {
13252 new_return(10);
13253 }
13254
13255
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13256 {
13257 new_return(11);
13258 }
13259
13260
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13261 {
13262 new_return(12);
13263 }
13264
13265 //de-endianfy the data
13266 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13267
13268
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13269 {
13270
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13271 {
13272 new_return(13);
13273 }
13274 18594894 }
13275 820 }
13276
13277
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13278 {
13279 6 section_size=writesize;
13280 6 }
13281 12 }
13282
13283
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13284 {
13285 char ebuf[80];
13286 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13287 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13288 }
13289
13290 6 new_return(0);
13291 }
13292
13293 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13294 {
13295 6 dword section_id=ID_INITDATA;
13296 6 dword section_version=V_INITDATA;
13297 6 dword section_cversion=CV_INITDATA;
13298 6 dword section_size = 0;
13299
13300 6 zinit.last_map=Map.getCurrMap();
13301 6 zinit.last_screen=Map.getCurrScr();
13302 6 zinit.normalize();
13303
13304 //section id
13305
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13306 {
13307 new_return(1);
13308 }
13309
13310 //section version info
13311
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13312 {
13313 new_return(2);
13314 }
13315
13316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13317 {
13318 new_return(3);
13319 }
13320
13321 //TODO
13322
13323
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13324 {
13325 12 fake_pack_writing=(writecycle==0);
13326
13327 //section size
13328
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13329 new_return(4);
13330
13331 12 writesize=0;
13332
13333
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13334
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13335 new_return(5);
13336
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13337 {
13338
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13339 new_return(6);
13340
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13341 new_return(7);
13342
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13343 new_return(8);
13344
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13345 new_return(9);
13346 768 }
13347
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13348 new_return(10);
13349
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13350 new_return(11);
13351
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13352
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13353 new_return(12);
13354
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13355
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13356 new_return(13);
13357
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13358 new_return(14);
13359
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13360 new_return(15);
13361
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13362 new_return(16);
13363
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13364 new_return(17);
13365
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13366 new_return(18);
13367
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13368 new_return(19);
13369
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13370 new_return(20);
13371
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13372 new_return(21);
13373
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13374 new_return(22);
13375
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13376 new_return(23);
13377
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13378 new_return(24);
13379
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13380 new_return(25);
13381
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13382 new_return(26);
13383
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13384 new_return(27);
13385
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13386 new_return(28);
13387
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13388 new_return(29);
13389
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13390 new_return(30);
13391
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13392 new_return(31);
13393
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13394 new_return(32);
13395
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13396 new_return(33);
13397
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13398 new_return(34);
13399
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13400 new_return(35);
13401
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13402 new_return(36);
13403
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13404 new_return(37);
13405
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13406 new_return(38);
13407
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13408 new_return(39);
13409
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13410 new_return(40);
13411
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13412 new_return(41);
13413
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13414 new_return(42);
13415
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13416 new_return(43);
13417
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13418 new_return(44);
13419
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13420 new_return(45);
13421
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13422 new_return(46);
13423
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13424 new_return(47);
13425
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13426 new_return(48);
13427
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13428 new_return(49);
13429
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13430 new_return(50);
13431
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13432 new_return(51);
13433
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13434 new_return(52);
13435
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13436 new_return(53);
13437
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13438 new_return(54);
13439
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13440 new_return(55);
13441
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13442 new_return(56);
13443
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13444 new_return(57);
13445
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13446 new_return(58);
13447
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13448 new_return(59);
13449
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13450 new_return(60);
13451
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13452 new_return(61);
13453
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13454 new_return(62);
13455
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13456 new_return(63);
13457
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13458 new_return(64);
13459
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13460 new_return(65);
13461
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13462 new_return(66);
13463
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13464 new_return(67);
13465
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13466 new_return(68);
13467
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13468 new_return(69);
13469
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13470 new_return(70);
13471
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13472 new_return(71);
13473
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13474 new_return(72);
13475
13476
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13477 {
13478 6 section_size=writesize;
13479 6 }
13480 12 }
13481
13482
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13483 {
13484 char ebuf[80];
13485 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13486 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13487 }
13488
13489 6 new_return(0);
13490 }
13491
13492 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13493 {
13494 //these are here to bypass compiler warnings about unused arguments
13495 6 Header=Header;
13496
13497 6 dword section_id=ID_ITEMDROPSETS;
13498 6 dword section_version=V_ITEMDROPSETS;
13499 6 dword section_cversion=CV_ITEMDROPSETS;
13500 // dword section_size=0;
13501 6 dword section_size = 0;
13502 6 word num_item_drop_sets=count_item_drop_sets();
13503
13504 //section id
13505
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13506 {
13507 new_return(1);
13508 }
13509
13510 //section version info
13511
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13512 {
13513 new_return(2);
13514 }
13515
13516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13517 {
13518 new_return(3);
13519 }
13520
13521
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13522 {
13523 12 fake_pack_writing=(writecycle==0);
13524
13525 //section size
13526
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13527 {
13528 new_return(4);
13529 }
13530
13531 12 writesize=0;
13532
13533 //finally... section data
13534
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13535 {
13536 new_return(5);
13537 }
13538
13539
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13540 {
13541
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13542 {
13543 new_return(6);
13544 }
13545
13546
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13547 {
13548
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13549 {
13550 new_return(7);
13551 }
13552 1580 }
13553
13554
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13555 {
13556
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13557 {
13558 new_return(8);
13559 }
13560 1738 }
13561 158 }
13562
13563
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13564 {
13565 6 section_size=writesize;
13566 6 }
13567 12 }
13568
13569
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13570 {
13571 char ebuf[80];
13572 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13573 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13574 }
13575
13576 6 new_return(0);
13577 }
13578
13579 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13580 {
13581 6 dword section_id=ID_FAVORITES;
13582 6 dword section_version=V_FAVORITES;
13583 6 dword section_cversion=CV_FAVORITES;
13584 6 dword section_size = 0;
13585
13586 //section id
13587
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13588 {
13589 new_return(1);
13590 }
13591
13592 //section version info
13593
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13594 {
13595 new_return(2);
13596 }
13597
13598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13599 {
13600 new_return(3);
13601 }
13602
13603
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13604 {
13605 12 fake_pack_writing=(writecycle==0);
13606
13607 //section size
13608
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13609 new_return(4);
13610
13611 12 writesize=0;
13612
13613
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13614 new_return(16);
13615
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13616 new_return(17);
13617
13618 12 word favcmb_cnt = 0;
13619
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13620
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13621 {
13622 8 favcmb_cnt = q+1;
13623 8 break;
13624 }
13625
13626
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13627 new_return(5);
13628
13629
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13630 {
13631
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13632 new_return(6);
13633
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13634 new_return(7);
13635 210 }
13636
13637
13638 12 word max_combo_cols = MAX_COMBO_COLS;
13639
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13640 new_return(9);
13641
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13642 {
13643
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13644 new_return(10);
13645
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13646 new_return(11);
13647
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13648 new_return(12);
13649 48 }
13650 12 word max_mappages = MAX_MAPPAGE_BTNS;
13651
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13652 new_return(13);
13653
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13654 {
13655
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13656 new_return(14);
13657
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13658 new_return(15);
13659 108 }
13660
13661
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13662 {
13663 6 section_size=writesize;
13664 6 }
13665 12 }
13666
13667
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13668 {
13669 char ebuf[80];
13670 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13671 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13672 }
13673
13674 6 new_return(0);
13675 }
13676
13677 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13678 {
13679
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13680 6 reset_combo_animations();
13681 6 reset_combo_animations2();
13682 6 strcpy(header.id_str,QH_NEWIDSTR);
13683 6 header.zelda_version = ZELDA_VERSION;
13684 6 header.internal = INTERNAL_VERSION;
13685 6 header.data_flags[ZQ_TILES] = true;
13686 6 header.data_flags[ZQ_CHEATS2] = 1;
13687 6 header.build=VERSION_BUILD;
13688
13689
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13690 {
13691 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13692 1512 }
13693
13694 char zinfofilename[2048];
13695 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13696
13697 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13698 6 box_out("Saving Quest...");
13699 6 box_eol();
13700 6 box_eol();
13701
13702
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13703
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13704
13705
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13706 return 1;
13707
13708
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13709
13710
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13711 return 2;
13712
13713
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13714
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13715
13716
13717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13718 {
13719 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13720
13721 box_out("Writing ZInfo...");
13722 if(inf)
13723 {
13724 if(writezinfo(inf,ZI)!=0)
13725 return 2;
13726
13727 pack_fclose(inf);
13728 box_out("okay.");
13729 }
13730 else box_out(" ...file failure");
13731 box_eol();
13732 }
13733 else
13734 {
13735
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13736
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13737 return 2;
13738
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13739
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13740 }
13741
13742
13743
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13744
13745
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13746 return 3;
13747
13748
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13749
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13750
13751
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13752
13753
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13754 return 4;
13755
13756
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13757
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13758
13759
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13760
13761
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13762 return 5;
13763
13764
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13765
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13766
13767
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13768
13769
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13770 return 6;
13771
13772
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13773
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13774
13775
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13776
13777
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13778 return 7;
13779
13780
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13781
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13782
13783
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13784
13785
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13786 return 8;
13787
13788
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13789
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13790
13791
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13792
13793
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13794 return 9;
13795
13796
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13797
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13798
13799
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13800
13801
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13802 return 10;
13803
13804
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13805
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13806
13807
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13808
13809
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13810 return 11;
13811
13812
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13813
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13814
13815
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13816
13817
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13818 return 12;
13819
13820
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13821
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13822
13823
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13824
13825
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13826 return 13;
13827
13828
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13829
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13830
13831
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13832
13833
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13834 return 14;
13835
13836
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13837
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13838
13839
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13840
13841
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13842 return 15;
13843
13844
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13845
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13846
13847
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13848
13849
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13850 return 16;
13851
13852
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13853
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13854
13855
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13856
13857
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13858 return 17;
13859
13860
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13861
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13862
13863
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13864
13865
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13866 return 18;
13867
13868
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13869
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13870
13871
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13872
13873
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13874 return 19;
13875
13876
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13877
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13878
13879
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
13880
13881
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
13882 return 20;
13883
13884
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13885
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13886
13887
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Hero Sprite Data...");
13888
13889
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
13890 return 21;
13891
13892
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13893
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13894
13895
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
13896
13897
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
13898 return 22;
13899
13900
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13901
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13902
13903
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
13904
13905
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
13906 return 23;
13907
13908
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13909
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13910
13911
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
13912
13913
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
13914 return 24;
13915
13916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13917
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13918
13919
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
13920
13921
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
13922 return 25;
13923
13924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13925
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13926
13927
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
13928
13929
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
13930 return 26;
13931
13932
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13933
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13934
13935
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
13936
13937
13938
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
13939 {
13940 char const* kfname = filename;
13941 char keyfilename[2048]={0};
13942 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
13943
13944 char temp_pw[QSTPWD_LEN] = {0};
13945 uint ind = 0;
13946 for(char const* ext : {"key","zpwd","zcheat"})
13947 {
13948 replace_extension(keyfilename, kfname, ext, 2047);
13949 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
13950 char msg[80] = {0};
13951 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
13952 msg[78]=13;
13953 msg[79]=10;
13954 pfwrite(msg, 80, fp);
13955 p_iputw(header.zelda_version,fp);
13956 p_putc(header.build,fp);
13957 char const* pwd = header.password;
13958 if(ind == 2) //.zcheat, hashed pwd
13959 {
13960 char hashmap = 'Z';
13961 hashmap += 'Q';
13962 hashmap += 'U';
13963 hashmap += 'E';
13964 hashmap += 'S';
13965 hashmap += 'T';
13966 for ( int q = 0; q < QSTPWD_LEN; ++q )
13967 {
13968 temp_pw[q] = header.password[q];
13969 temp_pw[q] += hashmap;
13970 }
13971 pwd = temp_pw;
13972 }
13973 pfwrite(pwd, strlen(pwd), fp);
13974 pack_fclose(fp);
13975 ++ind;
13976 }
13977 }
13978
13979 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
13980 6 std::error_code ec;
13981
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
13982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
13983 {
13984 al_trace("Error saving: %s\n", std::strerror(ec.value()));
13985 return ec.value();
13986 }
13987
13988
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
13989
13990 #ifdef __EMSCRIPTEN__
13991 em_sync_fs();
13992 #endif
13993
13994 6 return 0;
13995 6 }
13996
13997 // #ifdef _WIN32
13998 // static std::time_t to_time_t(FILETIME const& ft) {
13999 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14000 // t -= 116444736000000000ull;
14001 // t /= 10000000u;
14002 // return static_cast<std::time_t>(t);
14003 // }
14004 // #else
14005 // #endif
14006 template<typename TP>
14007 4 static std::time_t to_time_t(TP tp) {
14008 using namespace std::chrono;
14009 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14010 4 return system_clock::to_time_t(sctp);
14011 }
14012
14013 4 std::string get_time_last_modified_string(std::string path)
14014 {
14015
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14016 // TODO: C++20 but not supported yet.
14017 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14018 4 std::time_t tt = to_time_t(write_time);
14019 4 std::tm *gmt = std::gmtime(&tt);
14020 4 std::stringstream buffer;
14021
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14022
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14023 4 return formattedFileTime;
14024
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14025
14026 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14027 {
14028 // Always backup quest if it was last saved in a different version of the editor,
14029 // or if this a new file and is overwritting another qst file.
14030
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14031 {
14032 4 std::string backup_name;
14033
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14034
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14035 {
14036
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14037 4 }
14038 else
14039 {
14040 backup_name = fmt::format("{}", last_mod);
14041 }
14042
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14043
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14044
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14045 {
14046
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14047
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14048 {
14049
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14050 4 }
14051 else
14052 {
14053 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14054 }
14055 4 }
14056 4 }
14057
14058 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14059 6 fake_pack_writing = false;
14060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14061 {
14062 box_out("-- Error saving quest file! --");
14063 box_end(true);
14064 }
14065 6 else box_end(false);
14066 6 return ret;
14067 }
14068
14069 6 int32_t save_quest(const char *filename, bool timed_save)
14070 {
14071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14072
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14073 char ext1[5];
14074 6 ext1[0]=0;
14075
14076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14077 {
14078 sprintf(ext1, "qt");
14079 }
14080 else
14081 {
14082 6 sprintf(ext1, "qb");
14083 }
14084
14085
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14086 {
14087 char backupname[2048];
14088 char backupname2[2048];
14089 char ext[12];
14090
14091 for(int32_t i=retention-1; i>0; --i)
14092 {
14093 sprintf(ext, "%s%d", ext1, i-1);
14094 replace_extension(backupname, filepath, ext, 2047);
14095
14096 if(exists(backupname))
14097 {
14098 sprintf(ext, "%s%d", ext1, i);
14099 replace_extension(backupname2, filepath, ext, 2047);
14100
14101 if(exists(backupname2))
14102 {
14103 remove(backupname2);
14104 }
14105
14106 rename(backupname, backupname2);
14107 }
14108 }
14109
14110 //don't do this if we're not saving to the same name -DD
14111 if(!timed_save && !strcmp(filepath, filename))
14112 {
14113 sprintf(ext, "%s%d", ext1, 0);
14114 replace_extension(backupname, filepath, ext, 2047);
14115 rename(filepath, backupname);
14116 }
14117 }
14118
14119 int32_t ret;
14120 6 ret = save_unencoded_quest(filename, compress, filename);
14121
14122 6 return ret;
14123 }
14124
14125 6 void center_zq_class_dialogs()
14126 {
14127 6 jwin_center_dialog(pwd_dlg);
14128 6 }
14129
14130 void zmap::prv_secrets(bool high16only)
14131 {
14132 mapscr *s = &prvscr;
14133 mapscr *t = prvlayers;
14134 int32_t ft=0;
14135
14136 for(int32_t i=0; i<176; i++)
14137 {
14138 bool putit;
14139
14140 if(!high16only)
14141 {
14142 for(int32_t j=-1; j<6; j++)
14143 {
14144 int32_t newflag = -1;
14145
14146 for(int32_t iter=0; iter<2; ++iter)
14147 {
14148 putit=true;
14149
14150 if(!t[j].valid)
14151 continue;
14152
14153 int32_t checkflag=combobuf[t[j].data[i]].flag;
14154
14155 if(iter==1)
14156 {
14157 checkflag=t[j].sflag[i];
14158 }
14159
14160 switch(checkflag)
14161 {
14162 case mfANYFIRE:
14163 ft=sBCANDLE;
14164 break;
14165
14166 case mfSTRONGFIRE:
14167 ft=sRCANDLE;
14168 break;
14169
14170 case mfMAGICFIRE:
14171 ft=sWANDFIRE;
14172 break;
14173
14174 case mfDIVINEFIRE:
14175 ft=sDIVINEFIRE;
14176 break;
14177
14178 case mfARROW:
14179 ft=sARROW;
14180 break;
14181
14182 case mfSARROW:
14183 ft=sSARROW;
14184 break;
14185
14186 case mfGARROW:
14187 ft=sGARROW;
14188 break;
14189
14190 case mfSBOMB:
14191 ft=sSBOMB;
14192 break;
14193
14194 case mfBOMB:
14195 ft=sBOMB;
14196 break;
14197
14198 case mfBRANG:
14199 ft=sBRANG;
14200 break;
14201
14202 case mfMBRANG:
14203 ft=sMBRANG;
14204 break;
14205
14206 case mfFBRANG:
14207 ft=sFBRANG;
14208 break;
14209
14210 case mfWANDMAGIC:
14211 ft=sWANDMAGIC;
14212 break;
14213
14214 case mfREFMAGIC:
14215 ft=sREFMAGIC;
14216 break;
14217
14218 case mfREFFIREBALL:
14219 ft=sREFFIREBALL;
14220 break;
14221
14222 case mfSWORD:
14223 ft=sSWORD;
14224 break;
14225
14226 case mfWSWORD:
14227 ft=sWSWORD;
14228 break;
14229
14230 case mfMSWORD:
14231 ft=sMSWORD;
14232 break;
14233
14234 case mfXSWORD:
14235 ft=sXSWORD;
14236 break;
14237
14238 case mfSWORDBEAM:
14239 ft=sSWORDBEAM;
14240 break;
14241
14242 case mfWSWORDBEAM:
14243 ft=sWSWORDBEAM;
14244 break;
14245
14246 case mfMSWORDBEAM:
14247 ft=sMSWORDBEAM;
14248 break;
14249
14250 case mfXSWORDBEAM:
14251 ft=sXSWORDBEAM;
14252 break;
14253
14254 case mfHOOKSHOT:
14255 ft=sHOOKSHOT;
14256 break;
14257
14258 case mfWAND:
14259 ft=sWAND;
14260 break;
14261
14262 case mfHAMMER:
14263 ft=sHAMMER;
14264 break;
14265
14266 case mfSTRIKE:
14267 ft=sSTRIKE;
14268 break;
14269
14270 default:
14271 putit = false;
14272 break;
14273 }
14274
14275 if(putit)
14276 {
14277 if(j==-1)
14278 {
14279 s->data[i] = s->secretcombo[ft];
14280 s->cset[i] = s->secretcset[ft];
14281 newflag = s->secretflag[ft];
14282 }
14283 else
14284 {
14285 t[j].data[i] = t[j].secretcombo[ft];
14286 t[j].cset[i] = t[j].secretcset[ft];
14287 newflag = t[j].secretflag[ft];
14288 }
14289 }
14290 }
14291
14292 if(newflag >-1)
14293 {
14294 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14295 }
14296 }
14297 }
14298
14299 //if(true)
14300 //{
14301 int32_t newflag = -1;
14302
14303 for(int32_t iter=0; iter<2; ++iter)
14304 {
14305 int32_t checkflag=combobuf[s->data[i]].flag;
14306
14307 if(iter==1)
14308 {
14309 checkflag=s->sflag[i];
14310 }
14311
14312 if((checkflag > 15)&&(checkflag < 32))
14313 {
14314 s->data[i] = s->secretcombo[(checkflag)-16+4];
14315 s->cset[i] = s->secretcset[(checkflag)-16+4];
14316 newflag = s->secretflag[(checkflag)-16+4];
14317 // putit = true;
14318 }
14319 }
14320
14321 if(newflag >-1) s->sflag[i] = newflag;
14322
14323 for(int32_t j=0; j<6; j++)
14324 {
14325 if(!t[j].valid) continue;
14326
14327 int32_t newflag2 = -1;
14328
14329 for(int32_t iter=0; iter<2; ++iter)
14330 {
14331 int32_t checkflag=combobuf[t[j].data[i]].flag;
14332
14333 if(iter==1)
14334 {
14335 checkflag=t[j].sflag[i];
14336 }
14337
14338 if((checkflag > 15)&&(checkflag < 32))
14339 {
14340 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14341 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14342 newflag2 = t[j].secretflag[(checkflag)-16+4];
14343 }
14344 }
14345
14346 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14347 }
14348 }
14349
14350 //FFCs
14351 word num_ffcs = s->numFFC();
14352 for(word i=0; i<num_ffcs; ++i)
14353 {
14354 bool putit;
14355
14356 if(!high16only)
14357 {
14358 for(int32_t iter=0; iter<1; ++iter)
14359 {
14360 putit=true;
14361 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14362
14363 if(iter==1)
14364 {
14365 checkflag=s->sflag[i];
14366 }
14367
14368 switch(checkflag)
14369 {
14370 case mfANYFIRE:
14371 ft=sBCANDLE;
14372 break;
14373
14374 case mfSTRONGFIRE:
14375 ft=sRCANDLE;
14376 break;
14377
14378 case mfMAGICFIRE:
14379 ft=sWANDFIRE;
14380 break;
14381
14382 case mfDIVINEFIRE:
14383 ft=sDIVINEFIRE;
14384 break;
14385
14386 case mfARROW:
14387 ft=sARROW;
14388 break;
14389
14390 case mfSARROW:
14391 ft=sSARROW;
14392 break;
14393
14394 case mfGARROW:
14395 ft=sGARROW;
14396 break;
14397
14398 case mfSBOMB:
14399 ft=sSBOMB;
14400 break;
14401
14402 case mfBOMB:
14403 ft=sBOMB;
14404 break;
14405
14406 case mfBRANG:
14407 ft=sBRANG;
14408 break;
14409
14410 case mfMBRANG:
14411 ft=sMBRANG;
14412 break;
14413
14414 case mfFBRANG:
14415 ft=sFBRANG;
14416 break;
14417
14418 case mfWANDMAGIC:
14419 ft=sWANDMAGIC;
14420 break;
14421
14422 case mfREFMAGIC:
14423 ft=sREFMAGIC;
14424 break;
14425
14426 case mfREFFIREBALL:
14427 ft=sREFFIREBALL;
14428 break;
14429
14430 case mfSWORD:
14431 ft=sSWORD;
14432 break;
14433
14434 case mfWSWORD:
14435 ft=sWSWORD;
14436 break;
14437
14438 case mfMSWORD:
14439 ft=sMSWORD;
14440 break;
14441
14442 case mfXSWORD:
14443 ft=sXSWORD;
14444 break;
14445
14446 case mfSWORDBEAM:
14447 ft=sSWORDBEAM;
14448 break;
14449
14450 case mfWSWORDBEAM:
14451 ft=sWSWORDBEAM;
14452 break;
14453
14454 case mfMSWORDBEAM:
14455 ft=sMSWORDBEAM;
14456 break;
14457
14458 case mfXSWORDBEAM:
14459 ft=sXSWORDBEAM;
14460 break;
14461
14462 case mfHOOKSHOT:
14463 ft=sHOOKSHOT;
14464 break;
14465
14466 case mfWAND:
14467 ft=sWAND;
14468 break;
14469
14470 case mfHAMMER:
14471 ft=sHAMMER;
14472 break;
14473
14474 case mfSTRIKE:
14475 ft=sSTRIKE;
14476 break;
14477
14478 default:
14479 putit = false;
14480 break;
14481 }
14482
14483 if(putit)
14484 {
14485 s->ffcs[i].data = s->secretcombo[ft];
14486 s->ffcs[i].cset = s->secretcset[ft];
14487 }
14488 }
14489 }
14490
14491 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14492 {
14493 for(int32_t iter=0; iter<1; ++iter)
14494 {
14495 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14496
14497 if(iter==1)
14498 {
14499 // FFCs can't have flags! Yet...
14500 }
14501
14502 if((checkflag > 15)&&(checkflag < 32))
14503 {
14504 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14505 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14506 }
14507 }
14508 }
14509 }
14510 }
14511